22:44 from Doncaster, due into King's Cross 01:05 actually coasted into the terminal station at 00:40. Is this typical for the last train of the night or was I just incredibly lucky?
Trains late in the evening have a lot of slack built into their schedules to allow for short-notice diversions which might be required to fix problems reported during the day or planned engineering work.
In the instance of this train, 0105 is likely to be a worst case time for going via Hertford North or using the slow lines and getting stuck behind a stopping train. If all lines are open and it can run at line speed it will arrive early.
You can see that the timings allow for this train to follow the 2320 Peterborough to Kings Cross and 2335 Cambridge to Kings Cross if only one line is open into the terminal.
Passengers would be somewhat annoyed if it was scheduled for 0040 and arrived at 0105 whereas they might welcome arriving at 0040 if it is timetables at 0105.