From what I understand, there are several different theories about what dreams are, these being the major ones:
Some scientists have said that these 'scenarios' are the result of random firing of nerve cells in the brain, which stimulate random ideas, and the brain tries to connect these ideas by filling in the gaps with your subconscious. This means that dreams are a combination of randomly generated ideas and your own default thoughts.
Others believe the function of a dream to be weaving new material into the memory system in a way that both reduces emotional arousal and is adaptive in helping us cope with further trauma or stressful events.
Yet another model proposes that dreams function as a form of psychotherapy. In this theory, the dreamer is able to make connections between different thoughts and emotions in a safe environment.
Related Information on The All About Psychology Website