REM sleep is not fully understood, but a way to think about it is that the visual system is operating on “free-cycling autopilot”, unconstrained by the outside world.
Think for a moment about freeform dancing, “dancing like no one is watching.” Or similarly, think about how a baby moves when it is on its back in a crib. Where are the movements coming from? Are we “trying” to do anything? What makes the movements feel “creative” and “expressive” but not necessarily purposeful or goal directed?
During normal vision, the visual system is locked to the external world, trying to link an internal story with an external reality so that what you see is grounded in what is out there. The eyes search around to collect information in order to keep the internal story synchronized with the outside world, all while serving the information needs of our current goals and plans.
But in sleep, with eyes closed, there is no external reality to lock to; and there is no internal program trying to survive via sensory-perceptual traction. In dreaming, the mind can run free and carry the visual system along with it for the ride.
So the visual system goes through the motions, “looking” here and there. But what we see comes not from the environment, but filled in by our mind and memories. We “see” things generated by our brain, and then glance to one side to “find out more” and then more is generated. No matter where you look in your dream, there is more to see because the brain just keeps filling things in with something sort of reasonable.
And meanwhile, the eyes keep moving around because the mechanical system of visual attention direction hasn’t been disabled.
The limbs are paralyzed during dreaming to prevent dangerous movements, but this is not a problem for the eyes, so they move around, seemingly randomly.