The glitch was in reporting first place. If those two cars crossed the finish line before you did, they technically won anyway. There is no way to know precisely when they crossed the line, just that the game counts them as bring in the pit box immediately when they enter the pit. the pit boxes are after the line on the beginning of the next lap.
I have lost this race and Spa in exactly the same way more than once.
If you're burning through the final chicane on either track and an AI car enters pit road before you cross the start/finish line, they'll "pass" you automatically and if they were on the same lap as you, you'll lose to them.
Don't be in the pit when a race ends, and however long your put stops are taking, try and win by that amount of time at least. On those two races the AI is cheap like that. At The Human Comedy it's not as big of an issue. The AI attempted to simply chase me down at Kyoto, Tsukuba, and Red Bull Ring, leaving me to win by less than five seconds at each. At Autopolis, Alsace, and Deep Forest I embarrassed them all by several laps. I haven't golded the last two yet.
The best strategy for Le Mans is a 787b with IM tires and 8 laps like a scolded cat. If you don't have that car, any Mazda with a classic 26B engine will do, or you can use anything with the R92 engine or an F150 or F1500, the only differences in those last two are a zero and one goes muddin'.