Wilson started a series of experiments to study this more. And through his experiments he has come up with a theory, not just about rats, but about people too: When you sleep and when you dream you are reworking, or consolidating, your experiences from the day. Specifically you are consolidating new memories and making new associations from the information you processed during the day. Your brain is deciding what to remember and what to let go of, or forget.

https://www.blog.theteamw.com/2011/01/27/100-things-you-should-know-about-people-55-during-sleep-you-consolidate-learnings-and-memories/