This is still an open question being actively researched. There's some evidence that dreaming is the subjective experience we have when the brain is cleaning out its daily short-term memories and creating long-term ones, which are stored in a different way. A person's brain stops working well after a few days if they are prevented from dreaming (by waking them at the start of each REM cycle). Instead, they'll start to hallucinate while awake. So dreaming seems to be pretty important.
It's likely not just we humans who dream. Mammalian brains, in general, display REM cycles. Of course, the experience of dreams is subjective. I can see my cat having a REM cycle, but I can't conclude he's dreaming because threre is no way to experience the world as he does. But if I watch him or wake him up, he sure shows all the signs that, in fact, he is dreaming, at least to the degree his level of consciousness permits the word "dream" to apply to him.