my mom has an 06 corolla s and like the good son i am i do all the maintenance work

but im just curious because i dont drive it very much she forgot to tell me when she hit 3000 miles so she drove until it hit 5000, and service engine light came on.
now i dont have a problem im just curious how this works because i know the light will come on at 5000 if the oil is not changed. how does the car kno the oil was or was not changed? since now i make sure i look to see when it hits 3000 when i change it and the light never comes on.
i like to know about how stuff works so thats why i am asking