You can swap bikes in the middle of the race if you have a mechanical issue. There was one famous time where someone climbed impossibly fast, had a mechanical at the top of the mountain, then finished the race on a different bike, leading us to forever wonder.
That seems like an issue with checking though. If you know people can switch bikes mid race, meaning it's allowed by rules then it is simply stupid to only "double check" the winning bikes that made it to the finish line. Obviously you would need to check every single bike someone used during the race. That's different from someone illegally changing bikes.
This is what they do, for what its worth. Every team bike is subject to random or suspicion based inspection both pre-stage and post-stage. There's also in-stage monitoring that flags riders or their equipment for additional investigation.
The first athlete to be sanctioned for mechanical doping did exactly that. Inspectors found a bicycle in her pit with a hidden motor. Her excuse was "the bicycle was owned by a friend and was taken to the pit in error". The bike looked exactly the same as the bike she was riding.
https://en.wikipedia.org/wiki/Femke_Van_den_Driessche#Allega...
Except in cyclocross you swap bikes constantly during the race so the current one can be cleaned of mud before it blocks the wheels from spinning.