This happens when your computer goes into sleep mode, it takes a little bit to get a computer into its sleep mode depending on the computer. If you reopen it as soon as you close it, it will still go to sleep while the lid was just reopened.
If you don't want the computer to go into sleep mode...