In photos of doubleheaded trains back in the days of steam one always sees both locomotives facing forward...why were steam locomotives never coupled so that the second locomotive faces backward (to eliminate the need to turn one of them at the other end)? Did they not run well backward or were there other reasons?
The reasons already given by others are correct, most steam engines are designed to run forwards, and tracking at speed running backwards could be rough.
Where the second engine was a helper locomotive in a helper district, usually at the top of the grade there would be a wye, occasionally a turntable, and the helper would turn around while it waited for orders or signals to return to the start. (When the helper district was very short, sometimes the helper would back down to its origin at reduced speed.)
Where double heading was over the entire subdivision, recall that in the steam era run-through trains were less common and trains would typically be yarded. The caboose (often assigned to each conductor) would be removed, and the engines would head to the shop facilities for coal, water, sand and the various other servicing. A turntable was usually available, sometimes a wye.
So, there were many very good reasons for the locomotives to both face forward, and the physical plant was set up to make it easy to operate that way.
In today's bare-bone railroads, turntables are rare and many of the wyes have been removed. Diesels don't care which way they face, so orientation depends on the operating needs. Some railroads preferred to have at least two facing forwards so if the
lead unit had to be removed for any reason, a second engine was
immediately available. If there are no turning facilities at the far end, at least one locomotive should face the opposite direction. Otherwise the orientation may just depend on how they were facing at the origin.