Why do we dream? - Amy Adkins - YouTube
The Continual Activation Theory proposes that the dreams result from your brain's need to constantly consolidate the long-term memories.
So, when the external input drops bellow a certain level, the brain starts generating data from your memory, resulting into dreams. This is like a screensaver for your brain, so it won't shutdown completely.