MacBook Pro sleeps randomly on the train
More than likely, the Reed switch1 that detects when the lid is open/closed is momentarily making contact and sending your MacBook into sleep/hibernation mode. It could be faulty. 

This YouTube video shows a MBP going to sleep when a magnet is applied to the area where the switch is located.

It's happening on the train because there is enough movement or bumps in the ride to cause the switch to close.  Closing and opening the lid "resets" the switch which then sends the signal to wake up.  Normally, these switches are pretty robust and movement like that of a vehicle isn't enough to to trip them, but I have seen defective ones that would fail by simply turning the machine upside down (Dell, not Apple).  That said, in over 25 years in IT, I can count the number of times on one hand I have seen this type of symptom.

If you still have Apple Care, take a video of the MacBook going to sleep on the train and how you wake it back up.  Take the video and the MacBook to Apple and have them fix the issue for you.



1 Wikipedia:  Reed switch The Reed switch is an electrical switch operated by an applied magnetic field