In lobbies if you enter the track instantly after a race the distance driven in the previous race is wiped. Has been a bug in GTS too.
The workaround is to exit the track after the race, change to another car and then back to the other, that way mileage will be saved.