I think it's a pretty stupid question to begin with as it ignores visas. Also, too many different gauge widths means far too many train changes to be considered a part of the same journey.
If your definition includes a visa-free journey with no need to change trains, then the theretical limit is pretty easy to figure out: Minsk - Vladivostok. The second longest theoretical journey would probably be northern British Colombia down to Mexico / Guatemala border.
Because not only does the train trip become theretical, but so does the person taking the trip.
There's zero people in this world that don't have to avoid certain countries. Even if you magically get a visa for every country (and I would only describe 1/4 visas in my passport as trivial), that's not a guarantee you will be able to actually enter and leave the country uninterrupted.
Every single person that visited a ridiculous amount of countries has at least one story to tell about how they were apprehended and accused of being a spy. Using fringe little train lines usually not taken by anyone non-local would raise even more red flags than doing the same with other types of transport (motorcycle / bike / car).
There's nothing magical about getting to travel to the countries in this trip (I'm not the world's biggest traveller, and I've visited all of the ones in the longest trip he lists except 2 - and those two would be trivial to add too).
Paranoid much? It's not for the average Joe Tourist, but tons of people do such big trips (including friends). And I know people who did it in way more dangerous itineraries. Think Africa or Latin America.
Actually, a friend finished Canada all the way down to Tierra del Fuego Argentina 2 years ago on bike, and I'd be much more worried for some of the Central and Latin American countries he passed, than e.g. the train trip from Portugal across Europe to Singapore via China. Aside from the currently in effect sanctions against Russia, those are all trivial.
I don't even know what "There's zero people in this world that don't have to avoid certain countries" is supposed to mean. Why would they have to avoid certain countries (aside from not having the guts, or following some state "advisory")? Are they wanted or something?
Trivial matter 99% of time for a very narrow subset of the world's population (probably on the order of 5-10%). Often a very difficult and expensive process for the rest of us.
If your definition includes a visa-free journey with no need to change trains, then the theretical limit is pretty easy to figure out: Minsk - Vladivostok. The second longest theoretical journey would probably be northern British Colombia down to Mexico / Guatemala border.