I think it is linked to qualifying, at least partially.
When you skip qualifying on a 20 lap race, ai will mostly pit at lap 5-6. Run the qualifying to the end (15 minutes) and if you have adjusted their starting fuel level and max fuel level accordingly, they will pit at around 9-11 laps. I always put some extra fuel load there because obviously ai pits whenever the yellow gas tank alert appears (which means there's still fuel for at least 2 laps).
It's the exact same thing when you do your own qualifying. You need at least 2 full laps before you can see your fuel/laps requirement for the race. I think ai has the same problem, not enough QF laps it can't determine its required fuel / laps.
Of course this all requires that you set cars' max fuel from the car data so that they have fuel only for max 13 laps.
Then there are that idiotic "random variable" in the code, which makes some cars still pit at around lap 6. I guess there's no way to fix this. If CM had option "max pitstops per race", it would be great.
Summarizing a bit of my experience in "quick races" in various categories.
1. For me, qualifying is just (testing with different cars) to try and balance the "BoP" later.
Main influence of (performance) on the cars "AI"
a) "power.lut" file
b) "ai" file from the "DATA" folder
2. Normally I only do races, without qualifying, in most single-seaters (10/15% of the course) and usually 3/4 of the fuel in the tank.
The exception is the official EA/Codemasters games. The various races I've done in recent years, the 50s, 60s, 70s, 80s, 90s were with this percentage, in my case, very good (without pit stops).
The most complete so far are the 1950, 1970 and 1975 seasons and Mille Miglie '55 (in progress).
3. Long runs: I simulate the maximum amount of time and then gradually increase the time.
24h (Le Mans, Spa, Nurburgring) = maximum 1h
Indy 500 = 40/50 laps
12h (Sebring) = around 45 min
10h (Petit Le Mans) = around 35/40 min
8h (8h Bahrain and similar) = around 30 min
6h (current WEC type) = 20/25 min 4.
Currently mapping races in various categories from 2025: F1, F2, F3, Indy, WEC, IMSA, MotoGP, Stock Brasil, Supercars, SuperGT NASCAR, TCR, DTM, Rally...but the main simulator in most categories is Assetto Corsa, and in the first races I didn't have serious (AI) problems.
As previously mentioned, I also have other simulators, LM Ultimate, AMS 2, Dirt Rally 2, ACC, NASCAR, EA WRC, etc., and now Project Motor Racing and Assetto Rally are arriving.
But the question remains: where can we find practically all the major world categories, from the last century onwards, and be able to simulate a Targa Florio (we have the track, even a dirt one), not to mention the cars.
At the moment I'm simulating a "Mille Miglie (1955)", practically all the cars (even if some are generic).
The actual track doesn't exist in Assetto, but I use it sometimes (rally sections, long circuits, short circuits, tight sections, inclines and declines, etc., to simulate the real course).
If we want to simulate "Le Mans", we have a lot of things from the first version in 1923... (I myself did some qualifying simulations with several cars from each year).
The World Endurance Championship (WSC since 1953) is also well represented.
NASCAR and Indy (also very well represented) Touring Car and Rally categories (others that I really appreciate) Dakar Rally (we have that too).
Single-seaters besides F1 (F3, F2, F4 at the moment, with emphasis on the most recent ones), but we have some vintage ones.
I believe Assetto will (be in homes) for a long time to come.