Neat mod!
I think you copied some of the logic from Vehicle Wagon, but there is a better way to do it now (that I haven't updated Vehicle Wagon with yet). Set "allow_passengers" to false in the entity prototype. It even updates the tooltip to show that you can't get into it. No need to use control.lua or events at all, and it won't confusingly teleport players when they get in and immediately out of the wagon.
https://wiki.factorio.com/Prototype/Vehicle#allow_passengers
You'll have to do a search in data-final-fixes
to set the flag on every rolling stock that you don't want to be ridable, and make your setting startup settings.