Viennese Psychiatrist Sigmund Freud first developed the theory about the role of the unconscious on the individual.
Freud believed the dream worked on two levels. A straightforward level showed events in dreams as remembered. However in the latent level objects and actions in the dreams symbolize sexual and aggressive feelings and ideas that are repressed.
So in dreams it protects the sleeper from the effects of a realization of these wishes. The dream taps into the desire for wish fulfilment when the controlling ego is relaxed during sleep.
Freud wrote "All dreams are in a sense dreams of convenience, they help to prolong sleep instead of waking up. Dreams are the guardians of sleep and not its disturbers.