Umm... Wow. There's two issues here.
First, cars that have finished are ranked higher than cars than haven't if they have completed the same number of laps. The order changes as cars then finish. If you start your 27th lap before the timer expires, you have completed 26 laps. If an AI car then finishes its 26th lap after the timer expires, it has completed 26 laps and finished. It will be ranked ahead of you until you finish - then you'll have completed 27 laps and finished and be ranked ahead of it.
This is exploitable by the player, but not the AI - you can allow the AI to start a lap it will not finish within the 4/9/24 hours, wait for the timer to expire and then cross the line to finish behind it, but you'll be ranked ahead of it temporarily. You can then "X" through the screens quickly to be given 1st place credit, credits and XP.
The second issue is the "Time Limit" which appears in the bottom-right corner with around an hour to go to the end of an endurance race and counts down from 59:59. Many people have noticed that, in the longer timed endurance races (9/24 hours), it doesn't tally with the actual length of time the endurance race is supposed to last. What it appears to do (I can't say for sure) is count down what it predicts to be the end of the leader's last possible completed lap within the time allotted. What I'd then guess is that it does this because PD have accounted for 24 hour race tradition where only the second-last lap is a full speed racing lap, with the last lap (the lap on which the full race length expires) being a lap of honour - a lap of honour after the time on an 8/14 mile race track is unfeasible - allowing for the drivers to thank the marshalls and all those pretty photos of teams' cars crossing the line together. This has happened at the real Le Mans for sixty years - with the occasional rare exception, like 2011 (the first, full-pace last lap for forty years), where the lead cars are so close to each other that the last lap can make a difference.
Which is pretty neat when you think about it.