It's because of REM cycles (I'll assume you know what those are, if not they're easy to google ). You know how they get longer with shorter breaks between throughout your sleep cycle, so that after like 10 hours' sleep you're almost in continuous REM? Somehow those cycles continue even when you're awake, so that if you go back to sleep you're already in REM, but a few hours after getting up for the day it resets.