Commuter trains would be arranged for the most efficient turn around or based on local requirements.
Long distance trains up until Amtrak, as mentioned above would be arranged as follows:
RPO (if any)
Baggage (if psg/bag combine) coach end toward coaches)
Coaches
Diner (if any)
Pullmans
Observation
In the days of heavy travel, this did tend to put the diner toward the middle. The other consideration was that you did not have the coach passenger walking through first class (and vice-versa) to get to the diner. Pullman passenger were much fewer and paid much more the privacy. Also in steam days, the rear of the train was cleaner and quieter so again the RRs tried to give the higher paying customers a little more for their money. I don't know often or if lounges and observations were restricted to first class.
Another note, RPOs were locked. They were manned by USPS employees (required to be armed) and were locked. Passenger or train crew could not pass through them. although I would guess they would let train crew through if necessary. So they should be placed at end or the other. On long distance trains, sometimes passengers would want to access their luggage, so the might be taken to a baggage car. Access to express cars would be limited to train crew.
There was a lot of switching at major terminals and even some minor ones such as Wheeling WV. This would happen as trains from different origins were combined into trains to a single or fewer destinations. And trains would be broken up to go different directions where multiple lines exisited.
Also it was quite common in the pullman era for a pullman to picked at a station by an overnight train. If the business was there, the RR, would spot a pullman-sleeper at the station in the evening and allow passengers to boards, say at 9 or 10 pm. The passengers could bed down in their berths at a decent hours. At some point during the night a through passenger trains would stop and pick up the pullman and take it on to whereever. Generally it meant the passengers would arrive at their destination the next morning. My brother did that as late as the early 70s between Pittsburgh and Chicago.
The reverse would also happen, another train goind the other way would drop off a pullman at some point during the day.