Dreaming is universal, occupies a substantial portion of sleep, and has no agreed function. Several theories compete and the evidence is partial for all of them.
Memory consolidation
The best-supported idea. During sleep, the brain replays patterns from waking experience, and this appears to strengthen and reorganise memories.
Studies show improved performance on learned tasks after sleep containing the relevant stages, and disrupting sleep impairs it. Whether the subjective dream is part of the process or a by-product of it is unclear.
Emotional processing
Dreams contain disproportionate emotional content, and one proposal is that they let emotional memories be reprocessed with reduced stress chemistry present, softening their charge.
Consistent with the observation that disrupted dreaming is associated with worse emotional regulation, and with the prominence of dreams in trauma-related conditions.
Threat simulation
That dreams rehearse dangerous situations in safety, which would have had survival value. Dream content does skew towards threat and misfortune across cultures, which is suggestive rather than conclusive.
The by-product view
That dreams have no function – the brain is active during sleep for other reasons and generates experience as a side effect, which the waking mind then interprets as narrative.
Difficult to disprove and unsatisfying, which is not an argument against it.
What is actually known
That dreaming occurs in most sleep stages, not only one. That content relates loosely to waking concerns. That most dreams are forgotten within minutes.
And that despite a century of investigation, the question is open.