Once things like CANBUS became popular, as well as ECUs getting integrated with ABS/traction control, they'd look for drive wheels spinning and but not undriven wheels. When stability control systems became a thing, they could monitor steering angle and look for the car moving but not being steered, ditto for the accelerometer not detecting acceleration and cornering.
Tuners knew all about this shit because they disassembled ECU code and looked at ROM formats. They could point you right to the table used for when the ECU thought it was undergoing emissions testing. The cheating was plain as day and no government regulators cared enough to look. They probably even knew it was going on.
Here's the billion dollar question: the ECUs aren't developed by the car manufacturers. They aren't even coded by thr manufacturers. The car manufacturer just puts in maps for various engine parameters. The ECUs are supplied by companies like Bosch, Hitachi, Nippon-Denso, Magneti-Marelli, and so on.
They almost certainly knew this was going on and were complicit. Why have none of them been held responsible?