Why is the sun hurting my eyes?
Sunlight floods your retina faster than your eye can dim it, and bright light triggers a protective pain reflex.
Your pupil is a slow shutter
The colored ring of your eye, the iris, opens and closes a hole called the pupil to control how much light gets in. In dim light it widens; in bright light it shrinks. But it is sluggish, taking a second or more to react, so a sudden burst of sunlight gets through before the door can close.
The sun is roughly 100,000 times brighter than a comfortably lit room. Even a fully shrunk pupil cannot dim that much, so the overflow reaches your light-sensing retina at full force.
The retina overloads
Your retina is paved with photoreceptors, tiny cells that fire when light hits them. Under extreme brightness they fire all at once and bleach their light-sensitive pigment faster than it can regenerate, which is the overwhelmed, dazzled feeling you get.
Why it actually hurts
This light-triggered discomfort is called photophobia. It is not damage by itself but a warning system, the same nerve that senses pain in your face responds to bright light, nudging you to protect your eyes before harm is done.
Heed it. Staring directly at the sun can burn the retina (solar retinopathy), and there are no pain receptors deep in the retina to warn you while it happens. Sunglasses and a quick look away are the eye doing exactly what it should.