When we dream, our brain filters a fluid across something called the blood brain barrier, and “dirty” stuff is removed from our brain. It’s literally like emptying the trash, and this helps us store memories.
Its still a bit of a mystery, but our brain is still active even while we sleep. Some researchers say dreams have no purpose or meaning and are nonsensical activities of the sleeping brain. Others say dreams are necessary for mental, emotional, and physical health. There was a study done on those who were woken up before dreaming state, and they were more stressed and suffered depression, so dreaming is very important!