The reason that people need to sleep remains mostly a mystery, but many scientists believe that memory consolidation is part of it. Memory consolidation is the process by which recent memories are strengthened into long term memories. It is believed that memories are stored in the hippocampus for a short time, and that they are transferred to the cortex as part of consolidation.
An important thing to take away from this is that sleep reinforces learning. If you sleep after learning some material, you will remember it better than if you did not sleep. Thus, it is not advisable to study and take an exam on the same day. If you can sleep in between, the memories will have a chance to become consolidated and you will have better recall.