The phantom lights you see after a head injury aren't actually stars
When you bump your head and a sudden light show erupts in your vision, you aren't seeing celestial bodies. You are experiencing phosphenes: a trick played on your visual system by mechanical or electrical interference that mimics the presence of light.
The phenomenon of 'seeing stars' is actually the result of phosphenes—phantom lights produced when the visual system is manipulated. Your visual pathway relies on three primary components: the retina, which captures photons; the optic nerve, which transmits electrochemical signals; and the occipel lobe, the brain's initial sorting center for visual stimuli. When any of these parts are disturbed, the brain can misinterpret the signal, transforming a simple stimulus into a perceived flash of light.
These disturbances generally fall into two categories: mechanical and electrical. Mechanical stimulation can be triggered by physical pressure, such as rubbing your eyes, pressing the side of your eye toward your nose, or even the sudden pressure of a sneeze. It can even occur if a physical impact, such as being hit on the back of the head, causes the brain to move within the skull, suddenly stimulating neurons. Electrical stimulation is even more direct; using electromagnets near the occipital lobe or electrodes near the optic nerve can induce these lights. Remarkably, this process can even produce phosphenes in individuals who are blind due to retinal malfunction, provided the rest of the visual system remains functional.
Other physiological shifts may also play a role. For instance, standing up too quickly can cause a sensation of seeing stars, likely due to changes in the oxygen available to the retinal cells, the optic nerve, or the neurons themselves. While the universe contains up to one septillion stars, the lights dancing in your eyes after a bump to the head are purely internal, a momentary glitch in your biological hardware.
Source: Why Do We 'See Stars'?