Their theory is that dreams are like threat simulations for waking life. Early humans especially didn't know what life was going to throw at them day-to-day: tigers, lions, giant rampaging wombats. So evolution favoured folk whose anxiety dreams best prepped them for survival in the real world, letting them act out ways to confront (or avoid) danger.
This is based on the mere five per cent of dreams we can remember, mind you. Perhaps for the rest we really are drinking a milkshake with Benedict Cumberbatch while talking doves narrate our favourite podcasts and scatter confetti on our heads. We can only hope. There are five stages of sleep - most dreaming comes during the REM (rapid eye movement) stage. Scientists have known about REM since the '50s, and early research basically consisted of watching snoozing people's eyeballs jump around crazily behind their eyelids. Those '50s volunteers weren't getting much quality sleep, either, since they were woken up during REM and asked what they were dreaming about. Interestingly, eye movement and dream content seemed to match.