I think I’ll let my favorite neuroscientist, David Eagleman, explain it to you directly. Here’s an excerpt from his new book, Livewired: The Inside Story of the Ever-Changing Brain…
WHAT DOES DREAMING HAVE TO DO WITH THE ROTATION OF THE PLANET?
One of the unsolved mysteries in neuroscience is why brains dream. What are these bizarre nighttime hallucinations about? Do they have meaning? Or are they simply random neural activity in search of a coherent narrative? And why are dreams so richly visual, igniting the occipital cortex every night into a conflagration of activity?

Consider the following: In the chronic and unforgiving competition for brain real estate, the visual system has a unique problem to deal with. Because of the rotation of the planet, it is cast into darkness for an average of twelve hours every cycle. (This refers to 99.9999 percent of our species’ evolutionary history, not to the current, electricity-blessed times). We’ve already seen that sensory deprivation triggers neighboring territories to take over. So how does the visual system deal with this unfair disadvantage?
By keeping the occipital cortex active during the night.
We suggest that dreaming exists to keep the visual cortex from being taken over by neighboring areas. After all, the rotation of the planet does not affect anything about your ability to touch, hear, taste, or smell; only vision suffers in the dark. As a result, the visual cortex finds itself in danger every night of takeover by the other senses. And given the startling rapidity with which changes in territory can happen (remember the forty to sixty minutes we just saw in the blindfolded experiment), the threat is formidable. Dreams are the means by which the visual cortex prevents takeover.

To better understand this, let’s zoom out….During most of the night, there is no dreaming. But during REM sleep, something special happens. The heart rate and breathing speed up, small muscles twitch, and the brain waves become smaller and faster. This is the state in which dreaming occurs. The increased activity in these neurons has two consequences. The first is that the major muscle groups become paralyzed. Elaborate neural circuitry keeps the body frozen during dreaming….This muscular shutdown allows the brain to simulate world experience without actually moving the body around.
The second consequence is the really important one: waves of spikes travel from the brainstem to the the occipital cortex. When the spikes arrive there, the activity is experienced as visual. We see. This activity is why dreams are pictorial and filmic, instead of conceptual or abstract.
We theorize that the circuitry behind visual dreams is not accidental. Instead, to prevent takeover, the visual system is forced to fight for its territory by generating bursts of activity when the planet rotates into darkness. In the face of constant competition for sensory real estate, an occipital self-defense evolved. After all, vision carries mission-critical information, but it is stolen away for half of our hours. Dreams, therefore, may be the strange love child of neural plasticity and the rotation of the planet. ~ pp. 45-47