An April 2017 paper might lead to work that gives clues as to whether dreaming has a function.
F.Siclari et al. (2017). The neural correlates of dreaming. Nature Neuroscience, Nature Neuroscience, 20, 872–878 doi:10.1038/nn.4545.
Francesca Siclari and colleagues woke participants hundreds of times in the sleep lab and asked each time whether they were having a Dream Experience (DE), Dream Experience Without Recall of a dream (DEWR), or No Experience (NE).
They found that Brain activity associated with Dream Experience (DE), as compared to NE (No Experience), had reduced power in the 1–4-Hz band in a parieto-occipital region, that is lower amount of slow waves, which are associated with non-REM sleep. DE with recall of content, compared to DEWR (Dream Experience Without Recall) and NE, was associated with higher high-frequency power (more wakelike EEG) in medial and lateral frontoparietal areas.
So dreaming occurs in NREM sleep because the 'hot spot' is activated.
The next step would be to find out why the hot spot / dreaming, is turned on during sleep, and indeed during REM and non-REM sleep. We could ask the question, is virtual simulation of the world (i.e., dreaming) sometimes needed to complete/enhance memory processing that is occurring during sleep? Does the brain do some memory processing and then need to run a dream simulation to complete the processing?
Also, if we can find out why the 'hot spot' changes during sleep, with deep slow waves decreasing and fast waves increasing, that might give clues as to any function of this physiological change, and any function of the dreams that are then created.