Sleeping and napping help integrate new information into your brain. For example, if you are studying something and take a nap afterwards, your recall of the material is much higher. This principle also applies to exercise where the actual growth takes place after the workout when you’re resting. Similarly when learning a new physical skill, you can often notice a marked improvement the next day. You might also notice a worse effect if you keep at it too long, and might notice better results from short periods of intense learning alternating with lots of rest.
The lay-theory that I’m aware of is that dreams help understand the day’s work. Another interesting theory for dreaming is that it is a testing and improvement of our ability to model the world. In any case, this is a fairly robust finding. I’ve personally experienced this many times when I didn’t understand something before I went to bed but did when I woke up. Recently, I’ve been learning Dvorak, a new keyboard layout, and every day there is a marked improvement overnight. For example, yesterday I was typing at 12 words per minute, today I’m upto 21, overnight.
This seems weird if you think about it because our mental model of our minds is that it’s like a computer (a consequence of the cognitive revolution in psychology) but we don’t and we have to learn how to work with our minds to get the best results.
Here’s an XKCD comic for you: