It would seem like what you are experiencing is eidetic memory (Eidetikos) and/or Hypnogogia. Reasons as to how and why this may occur are still being studied. Consider the following here:
"Visual Cues for the Retrieval of Landmark Memories by Navigating Wood Ants" by
Robert A. Harris, Paul Graham, and Thomas S. Collett
Even on short routes, ants can be guided by multiple visual memories. We investigate here the cues controlling memory retrieval as wood ants approach a one- or two-edged landmark to collect sucrose at a point along its base. In such tasks, ants store the desired retinal position of landmark edges at several points along their route. They guide subsequent trips by retrieving the appropriate memory and moving to bring the edges in the scene toward the stored positions.<
Some ants, having located a reliable source of food, shuttle back and forth along idiosyncratic, visually guided routes (e.g., [1–5]); the final stage of their route to a goal is guided by a stored local view or snapshot of the surroundings as seen from a vantage point close to the destination (review ). A view of a familiar object stored as a snapshot seems to be encoded in terms of a small set of distinct features, such as oriented edges, color, and retinal size [7–9]. In some experimental situations, ants and bees attend to high-contrast boundaries of objects and guide their path to their destination by moving so as to shift edges in the current retinal image toward their stored retinal positions in the snapshot [7, 9]. If the visual scene is manipulated so that some edges are missing and cannot be matched to the snapshot, the insects will steer as best they can with the remaining edges [7, 9].<
What this seems to be like for us is what has been known as the "Method of Loci".
The method of loci is a strategy of memory enhancement which uses visualizations of familiar spatial environments in order to enhance the recall of information. The method of loci is also known as the memory journey, memory palace, or mind palace technique. This method is a mnemonic device adopted in ancient Roman and Greek rhetorical treatises.<
So, in one sense the brain may perform this operation for some purpose(s) of survival and navigation but these may not be the only reasons. Given that they emerge in these states as you describe makes it even more difficult to ascertain as you are presumably safe and are not in the process of moving about the room.
Also something to consider which I have shared before is the following paper on Electromagnetic Field Theories of Mind: https://philarchive.org/rec/JONETO?all_versions=1
Hope this helps!