But very often, the player does NOT want the unit to unload from the train, but instead was clicking on it because they wanted to move it (or maybe to move it) somewhere else before unloading it.
So please change it to where the player actually has to click on the "on train" button for a unit to unload. Units should never unload unless the player actually does something affirmative to indicate that they want it to actually unload.
Or, if for some reason you really want to keep the current behavior, have it be a game option that the player can select.
I was just now clicking on a unit on a rail, and it unloaded without me clicking to order it to unload (this happened earlier also). Just as an example, it happened with this unit just now, which had been on rail with 200 SMP:

It also happened earlier with a unit that was next to an enemy on a rail, so I was wondering if that might be why, but in this case it happened also with a unit that was NOT next to an enemy.