>>14278505When you sleep, your brain encodes shit you've recently experienced into long-term (longer-term?) memory via the hippocampus.
The thing is, the process sometimes 'glitches' and the brain mistakenly interprets the diarrhea of information being encoded as actually happening, hence why dreams can feel realistic while also frequently being an aimless batshit mess only tangentially recognizable as experiences, fixations, and uncontrolled semantic associations thereof.