Dreaming is one of the biggest mysteries of why. Most dreams occur during the rapid eye movement (REM) sleep cycle when we’re most deeply asleep, which is also when you remember it best. Some people claim that it’s connecting the emotional world to the real world.
Supposedly dreams are made up of what your brain sees each day. Every day our brains take in millions of pieces of information - everything you see or everything that happens. Some say we have dreams to help with the process of what to remember and what not to keep. Other people say it's because we're not focused. Our minds are often centered on doing a specific task during the day, but at night when we aren't focused at all, our imaginations our out and our connections are loose to do whatever it wants with our minds.
The truth is no one really knows for sure. Answering the the question as to which theory written about earlier is right, or whether dreaming comes from a biological, philosophical, or physical origin are still somewhat mysterious to people who study dreams. Even with lucid dreaming (any dream in which one is aware that they are dreaming) only some people can sometimes control their dreams, and no one knows why.
Also if you eat cheese before going to bed you're supposed to have really cool dreams!