A few years ago I travelled on the Trans-Siberian rail route. As a single woman, I got what in advance I would have called the worst possible option - in a room of 4 bunks there were 2 young Russian squaddies (I was almost old enough to be their mother) released from the best part of a year on the Russian-Chinese border.
It was great fun - yes, one of them propositioned me several times in the most polite way (speaking minimal English) - but they also made sure I knew when I could get off and on the train again without being left behind, bought local specialities at the stations where we stopped and insisted I share it with them, took 'no' for an answer, and when I finally got off (at Irkutsk) carried my bags for me until I found the guide who came to meet me.
Yes, I'm lucky I didn't have unresolved trauma (was abused by someone I knew as a teenager). But there are all sorts of situations where you might end up travelling in close proximity to a man, trans or otherwise. If that's too much of a risk for you, don't do it.
The Caledonian sleeper is not the only option for travelling that route (in fact, the time I went on it - because I love train journeys - it would have been cheaper to fly).