I've heard that dreams are the result of your brain trying its best to interpret random white noise that occurs while you sleep. It makes some amount of sense, since I know the brain is really good at taking input and parsing it in tricky ways to give you a full picture of the world around you with very limited information. Like, the only place in your line of sight that's completely in focus is an area approximately the width of your thumbnail held at arm's length right in the center of your field of view. All that peripheral vision and whatnot is mostly a recreation from previous experience coupled with stray light coming in at odd angles. It's a well-known fact that sensory deprivation tends to produce wild and crazy hallucinations, so dreams are sort of like those. You get these random electrical currents flitting about as your brain does its thing, keeping your heart going and all that jazz, and your sleeping mind tries to process that in the context of your normal waking world. But since it's working with nothing beyond random noise, you get some pretty funny results. The storylines and things you get are less what your brain put together when you were asleep and more what you try to put together once your faculties are active again.
I don't know. This is just what I've read. Makes sense to me. I've been keeping a dream journal lately in the hopes that I get some crazy spark for a short story from a dream (it's happened before), and looking back at some of the entries, I don't even remember writing them down, let alone dreaming them. I guess the latest one I was some guy who worked at a platform in the sky from which people launched hot air balloons, and my job was to drive out into the desert and drag back balloons that crashed. Or something. I didn't even write anything that coherent in the journal, so it's hard to tell what I was actually thinking.