I have wondered this too. What if dreams are a side-effect of a maintenance process, like if you were always kind and rewind your VHS but choose to watch them while doing so.
Also occurred to me (thanks to chatGPT) that dreams might be produced in the same way chatGPT produces narratives, by running through a series of "what is likely to be next according to my trained network" decisions