Production wise, in the days of physical models, it was easier to film them that way. Once CG became a thing, a matter of convenience, probably.
IMHO
Star Trek and
Star Wars spaceships are designed inaccurately. They have the direction of "downwards" caused by artificial gravity pointing perpendicular to the direction that the ship is traveling, similar to the natural gravity on ships at sea on Earth. Instead starships should be built like tall thin cylindrical skyscrapers, with many circular decks one above the other, and the direction of "downwards" caused by artificial gravity pointing toward the rear of the starship.
As one result of using such more correct designs, when two such starships coming from opposite directions met each other, their fronts pointing at each other, their top decks would be in front closest to each other and their bottom decks would in the rear farthest away from each other. There wouldn't be any question about how the top decks were aligned.
I do like it when other sci-fi shows play around with this trope. For example, in Stargate when they were fighting the Ori, everyone tries to position their ships either in front of or behind the Ori ships. The Ori ships break formation and attack from above and below, which no one is prepared for.
Then sometimes, it's taken too far, like in Star Wars Episode 3 when General Grievous's flagship is taken out it practically "sinks."
"in front of or behind the Ori ships"? "break formation"? "attack from above and below"? Obviously the creators of
Stargate imagined that space battles would be like in
Star Wars. The first rule of plausible space battles should be that 99.9 percent of the time things are different than in
Star Wars space battles.
With properly designed starships, their tops and fronts would be the same, and their bottoms and backs would be the same, and there would be various sides all around them.
Realistic starships would stay in their three dimensional formations in realistic space battles, because the distances at which they opened fire would be many times the distances between space battleships in battle formation.
If both fleets wanted to fight, they would travel toward each other and fire their lasers, phasers, particle beam weapons, missiles, kinetic weapons, and/or photon torpedoes when they came within range of those weapons - different types of weapons might have vastly different ranges and might be fired for the first time at different times and distances during the battle. Then they would reload and/or reenergize their weapons and fire again, and again, and again, during the battle.
The two fleets might flash through each other in an instant and continue to travel away from each other, firing their rear mounted weapons. If both fleets wanted to continue the battle, both fleets would decelerate and stop and then head back toward each other. They might do so by reversing their engines, if they could, and traveling backwards towards their enemies. If they couldn't reverse engines and travel backwards every ship would have to flip over 180 degrees to be pointed toward the enemy fleet to decelerate, stop, and then accelerate toward the enemy fleet.
If the weapons of Fleet A could destroy or badly damage ships in Fleet B at a much greater range, say twice the distance, that the weapons of Fleet B could destroy or badly damage ships in Fleet A, Fleet A wouldn't want to let Fleet B get close enough to use Fleet B's weapons. Fleet A would want to keep Fleet B within range of Fleet A's weapons while staying outside the range of Fleet B's weapons.
So in such a situation Fleet A would stop and reverse course after getting in range of Fleet B and beginning to shoot and would try to stay ahead of Fleet B at a great enough distance that fleet B couldn't hurt them. The fleet with the more powerful weapons would retreat from the fleet with the less powerful weapons hoping to devastate the pursuing fleet before they gave up the pursuit. If Fleet B with the lesser ranged weapons gave up chasing fleet A and stopped or turned around, Fleet A would stop and turn around and pursue Fleet B. In such a situation it would be possible for Fleet A to wipe out Fleet B without suffering any losses.
The outcome of a space battle would partially depend on which fleet had the fastest and/or fastest accelerating and decelerating ships, the more powerful and long range weapons, the best defenses such as anti missile missiles and force shields, etc., etc., and partially on which side used the best tactics to make the best use of their strengths and of the other side's weakness. But while the commanders on one side might know all about their own fleet's strengths and weaknesses, they might know somewhere between zero percent and one hundred percent about the other fleet's strengths and weaknesses and thus might choose disastrously incorrect tactics.
Suppose that a space warship is partially vaporized by the enemy's weapons. The vaporized material will spread out in an expanding cloud of incandescent glowing gas. Parts of the ship next to the vaporized part will be melted and turn into glowing hot liquid metal. The atmosphere contained within the melted parts will no longer be contained and will push out the molten walls that once held it in. Unless airtight doors are closed in time everybody aboard will die.
Meanwhile heat from the vaporized and melted parts of the hull will be rapidly conducted to the other parts of the presumably metallic hull. The hull will also heat up the air within the spaceship, probably hot enough to cause combustion of everything flammable on the ship, including the clothes of the crew. The crew will breath super hot, and possibly burning, air. The heated air will heat up any spacesuits any of the crew may be wearing, baking them inside the spacesuits.
Or possibly the space ship would be totally and instantly vaporized with everyone on board. All the material of the spaceship will become a rapidly expanding cloud of incandescent plasma. When the dimensions of the cloud double, the density of the cloud will decrease by eight times. When the dimensions of the cloud increase by three times, the density of the cloud will decrease by twenty seven times, and so on.
When the edge of the cloud reaches a neighboring ship in the fleet, the ship will be struck by the equivalent of a wind. Thus the fleet formation must have the ships spaced far enough apart so that an expanding cloud from a vaporized neighboring ship will be too thin to do any damage when it reaches the nearest ships. If missiles with atomic warheads are used the ships must be spaced far enough apart that a few nuclear explosions on one ship will not harm neighboring ships.
If the ships use matter-antimatter reactions for energy, vaporizing a ship will cause some of its stored antimatter to react with matter in a tremendous explosion. Thus the ships in a fleet must be spaced far enough apart that they will not be harmed by the largest calculated possible antimatter explosion on a neighboring ship. And the ships in a space fleet must be spaced far enough apart that they have room to maneuver without colliding.
Thus space battleships in a space war fleet should have a minimum spacing of somewhere between about 1 kilometer and 1,000 kilometers, I guess.
Thus one might imagine that a space fleet of 900 space battleships might be arranged in a square of 30 ships X 30 ships covering between 30 X 30 kilometers and 30,000 X 30,000 kilometers, or that a space fleet of 1,000 space battleships might be arranged in a cube 10 ships X 10 ships X 10 ships and being between 10 kilometers and 10,000 kilometers on each side.
As far as I remember, In some TOS episodes, phasers, disrupters, and photon torpedoes were fired at stated distances of tens of thousands or hundreds of thousands of kilometers. Thus TOS era space battles would be fought at distances from tens to tens of thousands of times as far as a fairly reasonable spacing between ships in a space fleet.