There are three scenarios:
1) Using a real train, commando style.
2) Using a real train, mostly or all filled by extras.
3) Fake train - not very common because it's usually obvious looking at the windows.
Proof of #2 are some vids where you see the same extra in two scenes. There was one convenience store vid where this happened and the extra was a real old lady.
Proof of #3 is obvious, but again not common.
For #1, once or twice a year a crew gets arrested for exhibition vids. Can't say specifically for trains but sure.
Some vids do #2 better than others, and in many vids they just have to make sure that there are enough extras to make it hard to see. This is especially true in the wide open "times square" pornos they do right outside the busiest stations. I did a double take when I realized I was just there in that exact spot months ago.