Randomly? Contrary to popular option, the AI drivers a rather dumb in that they follow orders explicitly and to the letter, with no deviation or initiative.
So if one is suddenly stopping, something just told it to; a wonky script, another train (AI or manually controlled) took control of a switch it needs, then later, if released, it can continue on it way as if nothing happened. Or it just recalculated its routing and discovered a shorter path because of changing conditions somewhere else on the map. If it was a transient condition the original routing will return, if not it might follow a new route to its destination.
Depending on what and how the orders are given, the routing can be obvious or not.