This is my understanding of how train-station-limits work:
- each station has a list of 'approaching trains'.
- this list has a maximum length of N.
- when a train wants to go to a station, it tries to put itself in the list, if the list is already full, it fails.
- the train tries another startion with the same name, if such a station exists.
- if no station with non-full 'approaching trains' list exists, the train will have 'no destination'
- if a station with non-full 'approaching trains' list exists, the train will register itself to the list, and head to it.
- the moment the train starts moving (from the station it is currently at), it deregisters itself from the list of its current station
- this means that other trains get notified and will attempt to visit the current station
So... when happens when we swap out a cargo-wagon, thereby destroying a train, and creating a new one...
- upon detroying it, it will deregister itself from the 'approaching trains' list of its destination
- upon recreating it, it will try to find a new destination, based on the station-name (it may have forgotten its previous target station)
This all is not really a problem, when the train is standing still at a station, and it doesn't have a route yet.
However, when the train is moving, the train may lose its place in the list of its target, and find no alternative, forcing it to stop.
To add insult to injury, once the train is on its ways, even when it moved 1 pixel, it deregistered itself from the current station, meaning other trains will move to the station. If the current train has no destination anymore, it will be stuck where it is, while other trains will target the current station, breaking the 'train limit' mechanic.