Answer:
According to many psychologists, we do not know why we dream when we sleep. There are many theories for sleep stemming from Freud to other modern psychologists.
We think that a lot of it stems from our pons in our brain. Our pons is in control of calming ourselves down from a fight/flight responses.
Freud's theory on dreams is that our subconscious' only way to communicate our deepest desires, lusts, wishes, etc. is through our dreams. Our conscious mind cannot comprehend these thoughts, so are buried down. Our subconscious tries to communicate these sorts of desires through dreaming.
However, other psychologists such as Hobson and McCarley believe that dreams are nothing more than our brain trying to make sense of random electrical impulses that happen during our REM sleep cycle.
When we sleep, random electrical impulses are sent through the brain stem. While motor and sensory cortexes normally handle these electrical signals, they are "turned off" when we sleep. Thus, these signals are sent to our frontal lobe which is where most cognitive thinking and reasoning are being held. This is where our brain tries to "make sense" of these signals by filling in memories as a blank.
However, these are both theories. Dream theories and why we dream are still being researched heavily.