Why do dreams occur? A more technical explanation would be that the brain is performing garbage collection, prioritizing and moving around memories that were formed during the waking moments. But that theory does not explain the kind of dreams I have.

I've had several types of dreams. I don't remember most of them. Of those I do, only very few have any connection to the real world. Many play out a mundane scenario that is real-world like, but the people and places are unfamiliar. It's like meeting new people, exploring new places, or living a new lifestyle. When dreams have real-world people or places, they tend to be mundane as well, but have a tendency to be slightly unpleasant.

I've had some dreams about future events that eventually unfolded in real-life. I don't keep a dream log, but the periods between the dream and the event don't appear to exhibit a pattern. Unfortunately, many of those are mundane as well, but somewhat distinctive from the daily routines enough to make me realize it's a deja-vu. It is hard to tell from the dream itself whether they are future-telling. Those dreams about unfamiliar people and places could be future telling dreams, but it's possible these dreams are simply a self-fulfilling prophecy.

Sometimes the best ideas come from a dream. I've transcribed a few songs that in my dream I have performed on stage. I've solved difficult computer design problems I was facing in the real-world. I've bought things for myself or others that only occurred to me in a dream. Contrary to ideas formed during waking moments, ideas from the dream are unpredictable and random. It kind of gives you the "life is a box of chocolate" feel for those who tend to live a very predictable life, so it gives you the outlook that anything is possible. That's why even if you dismiss dreams as a self-fulfilling prophesy, or if the dreams aren't actually fulfilled, an inspirational dream can still be a very powerful motivator. An experience of a dream is very real.

Of course some of the dreams defy laws of physics, so they are just fantasies, and I strongly suspect they will never happen in real-life.

Nightmares, on the other hand, is also very real. They tend be emotionally draining, especially those that your mind keeps torturing you over and over again. Nightmares are not constructive in any way unless you somehow find a solution to the problems presented there, either in the dream or while you reflect about it awake. Nightmares don't have to have any current real-life connections either, for example the recurring nightmare I have about taking exams. But it does remind me of a lifestyle I once had during a certain time of my life, and I would remember it enough to avoid going back to that situation.

Just like how sleep recharges the physical body, a dream recharges the mind. No matter how you interpret a dream, there is no doubt that having a good dream generally contributes to a person's well-being.