A recent article doesn't reach a firm conclusion, but offers two possible explanations.
Hiding is a behavioral strategy of the species to cope with environmental changes and stressors.
It keeps the cat at a comfortable temperature.
"Cats like boxes because they are cryptic animals; they like to hide,"And a box gives them a place of safety and security." While inside a box, cats feel that they cannot be snuck up on from behind or the side — anything that wants to approach them must come directly into their field of vision. In effect, such hiding spaces allow them to watch the world around them without being seen.
And if something interesting passes in front of the cat — be it prey or a toy — it can dash out to get the object, and then quickly return to its safety spot.
Boxes also provide cats with a cozy, safe place to sleep, which is very important given that the felines sleep for up to 20 hours a day.