Different theories give their own concepts for reason of dreams. The Greeks and Romans linked dreams with religious aspect, they believed dreams to be direct messages from God or from the dead. Ancient Egyptians wrote a dream book and described all the common dreams with their meaning.
Scientific study of dreaming is called ONEIROLOGY. Scientists have been performing sleep and dream studies for decades now but still aren't 100% sure about the functioning of brain. There have been researches which give us results just as assumptions and predictions. According to theory of certain researchers, certain memory processes can happen only when we are asleep, and our dreams are signal that these processes are taking place. Some have predicted that we dream to fulfill our wishes and the most interesting part is that we forget almost 95% of dreams we have, especially in the first 10 minutes of having it but the minor details that we remember after waking up symbolises the things we wish to achieve!
When we are discussing about dreams, the name which is the most worth mentioning here is Sigmund Freud. He gave the Psychoanalytic theory of dreams consistent with Psychoanalytic perspective. In the starting, Freud considered dreams to be royal road to unconscious world of our minds. In 1895, Freud had a dream which became the basis of series. In the year 1900, he proposed that all the dreams we see and even the nightmares are collection of images from daily conscious life but they also have some symbolic meaning which are for the fulfillment of the subconscious mind and the parts of dreams we remember after waking up have secret link to our desires, thoughts and urges. In his book 'The Interpretation of dreams' Freud wrote dreams are "... disguised fulfillment of repressed wishes".
According to Freud's Psychoanalytic view of personality, people are driven by aggressive and sexual instincts that are repressed from conscious awareness, while these thoughts are not consciously expressed, Freud suggested that they find way into our notice through dreams. He also described two components of dreams - Manifest content and Latent content. Manifest content is made up of the actual images, thoughts and content within the dream. On the other hand, Latent content represents the hidden psychological meaning of the dream. However, researches fails to demonstrate manifest content disguises the real psychological significance of a dream.
Carl Jung was a Swiss psychologist, who worked under Freud when he first started out in the field of psychology but he ended up spinltering when he disagreed on some assumptions made by Freud on psychology. Jung said that unconscious contains our personal unconscious means repressions from our private life as well as connection to collective unconscious meaning things repressed by the society and the whole humanity. So we are able to access symbols in our dreams that are instinctual to us and these are called archetypes.
Basically, archetypes are symbols that come up in dreams that have numinous significance. Jung's view about terms of wish fulfilment, was that Jung think of this as a reintegration process in a way of getting in touch with true self, our real existential nature which is deeply connected to everything and acts as a main driving force behind all the dream symbols coming so we can reintegrate those things.
Looking at all the view points, we come to the conclusion that dreams are continuation of things you keep talking about and thinking about in daily life and also your actual position in bed and the psychological things happening in your body have an impact on dreams you are having and guiding you in a magical way you certainly cannot predict anything about.