It would be designed so that nothing would happen. Again, you make it a passively cooled reactor where the entire unit is inside robust containment.Besides the other obvious safety concerns with putting a nuclear reactor in a train, there is one overriding concern that can be described in two words... Terrorist Target (a VERY attractive terrorist target). Imagine what would happen if a truck packed with explosives was run into the side of one of these trains in downtown Chicago.
Basically, take something like the MMR design (helium cooled), make it even smaller so its passive safety can be the actual containment structure, and further ruggedize it for this type of usage scenario:
From here: https://www.usnc.com/assets/media-k...chnical Information Document.pdf?v=4287b35212
Now, that unit is 5MWe (15MWth), which is ~6,700HP (20,000HP). Your typical diesel locomotive is 3-5,000HP and size would clearly be a design issue due to containment requirements:
But, it's technologically possible.
Now, is it financially viable? That's a very separate discussion and I'd argue, with the state of the US nuclear industry, no, it would be VERY difficult to make a financial case for something like this.
Highly recommend watching some of these tests for used fuel casks:
IAEA transport of spent nuclear fuel:
You'll note that we already transport this stuff by rail, road, ship and aircraft.