My guess is that the brain is trying new combinations, so that if you hit a new idea during the day, it will get reinforced (you get "excited"). So the brain "shuffles" stuff during the night (dreams) and during the day selects. It is like evolutionary modification of behavior, in a way.
But to do it, you have to reinforce a little the nonsensical stuff for a while (and at speed). This semi-conscious state in which there are inconsistencies is "pre"-dream, in which almost everything is quite nonsensical, but it kind of "makes sense", so it gets reinforced a bit. The interesting thing is that this is done in parallel, so what you remember about a dream is like a small part of what your cortex was "thinking", a massive recombination of ideas.
Well, I could go on and on with my speculations... ;)