A 2013 study in the journal Brain suggests that dreams are generated by the brainstem, which also regulates sleep. There is very little definitive science on how dreams occur in the brain.
In the study, dreaming is described as a "bottom-up" process, one in which dreams come from the same source as sleep regulation as opposed to the higher functioning parts of the brain. The study examined patients who lack the ability to activate any cognitive or emotional processes, known as auto-activation deficit. These patients typically describe their condition as the inability to have any thoughts at all, they are only able to respond to prompts or exhibit recall memory. However, in the study in question, patients with auto-activation deficit reported the ability to dream. If this is the case, it reflects that dream and the ability to activate cognitive processes are not necessarily linked.
The auto-activation deficit patients reported having fairly pedestrian dreams about normal behaviors rather than the surrealist fantasies which characterize conventional dreams. This suggests that dreaming is a process which can be described as a reflex, but that higher-order mental processes do have an impact on dreams. Indeed, it is those higher-order processes in people not afflicted with auto-activation deficit that produce the foreign dreams to which many people are accustomed.