Usually modern MCU stuff can detect power on resets and may or may not have non-volatile storage, and often have some kind of low power storage and RTC that is intended to be used with an external battery.
While the power is on, the MCU easily can detect how long it is turned on - save a flag e.g. while you're turned on for a certain amount of time, and reset that flag if the timing condition isn't met (too short or too long turned on). On next power on, read that flag from non-volatile or a "few seconds alive from a capacitor" storage", and increment a counter, otherwise reset that counter. If the counter reaches a certain value, do the factory reset.
I'd guess it's all implemented without any additional hardware. I'd guess too, it cannot detect the power off duration precisely (power on duration is easy in software), but something that just can discriminate between "longer than a few minutes" and "shorter than a few seconds" should be fine to do the job - might be an otherwise unused RTC within the microcontroller that is buffered by a small capacitor. So the criteria might be "RTC is still alive, or RTC has reset" to discriminate long or short "off".