This is caused by the train rolling while docking because of either unlevel tracks or a Locomotive or Car on a slope which will slowly pull the train out of the station. The current workaround is to manually control the train, back it out of the station and re-enter. Complete the docking manually to free it from being stuck in 'Docking' mode.
Note: you will need to hold 'space' to apply the breaks while docking to counter the movement of the train.
Once you have completed the docking manoeuvre manually, press 'C' to open the route planner and remove the route you have set temporarily then pull the train onto a section of tracks that is completely level so it doesn't decide to go for a roll.
You will now want to investigate each station to ensure that the entire length of the train is on a track that is supported by a foundation so it is completely level for 110% of the length of the train (1 tile before and after for good measure!)
Once you've made sure that all stations are perfectly level setup your route again and the train will then continue to run as expected. Hopefully, our benevolent corporate Managers at Coffee Stain Ficsit will update our trains with slightly more advanced firmware capable of applying the damn breaks while stopped soon!