

We are comparing attaching a diesel engine via a gearbox to attaching it via generator and electric speed controller.
Electrically driven wheels can deliver just the right amount of power at over 95% efficiency. Direct ICE suffers because it cannot always run the engine in ideal conditions, reducing its efficiency.
We do this in locomotives but not in cars because cars need to be lightweight. Actually, nuclear is clearly the best vehicle propulsion, almost infinite range and high power. It is only used in ships due to its weight.
I’m not claiming that electric transmission is more efficient always because it isn’t. But as you say it is close.
In a scenario where a train drives at a constant speed forever, attaching the engine to the wheels directly is a clear winner.
However, with varying torque requirements, an ICE can’t always operate at maximum efficiency. They are especially bad at starting from a standstill. You can get a good overview of the concept from this wiki article. https://en.m.wikipedia.org/wiki/Power_band