Loosen the strings on your guitar so vibrations don't break them. Place a cloth between the strings and the fingerboard so the strings don't push against it, causing damage.
Place the guitar in a hard case, not a soft case. You never know what storage options will be available to you on the train, so you need an external case that will protect the guitar. This will also help if the train ride is bumpy; your guitar will be safer.
Hold the guitar while on the train in your lap or between your legs. Don't put it in the overhead compartment because it won't fit properly and could be damaged due to jostling. If you're traveling a long distance, consider purchasing the seat next to you for your guitar.