Why do I always close my eyes when someone takes a photo of me using a flash?
What you are describing is called a "corneal reflex" and it is a measure to protect the eye from too bright light or foreign bodies.

It is a involuntary movement (i.e. not intentional, as you say), mediated by the cranial nerves, specifically the ophtalmic branch of the trigeminal and the temporal and zygomatic branches of the facial nerve.

I have to admit that I had a very hard time finding an exact complete explanation of the phenomenon, which makes me think (but I may be wrong) that it has not been widely researched. Although it is not difficult to imagine how the trigeminal nerve could be stimulated by a foreign body touching the cornea, it seems that several theories exist on how light can stimulate it.

The great part of the information that I could find at this regard are about a similar reflex, called the  the photic sneeze reflex or or ACHOO (Autosomal Cholinergic Helio-Ophtalmologic Outburst) syndrome. This occurs in ~1/4 of the population, and consists of sneezing when looking at the Sun.

In this case, several theories have been proposed, that essentially boil down to the fact that some other nerve (e.g. the optic nerve) stimulates the trigeminal after having being itself stimulated by bright light.

From: "General anaesthesia and the photosternutatory reflex" - Yarrow - Anaesthesia. 2003


  The physiology underlying the photosternutatory reflex remains unclear and several mechanisms have been proposed. The theory of optic-trigeminal summation holds that the optic and trigeminal nerves are intimately linked in the midbrain. Bright light stimulates the optic nerve, causing photophobia and pain via the ophthalmic branch of the trigeminal nerve. Conversely, nasal irritation can lead to blinking and lacrimation. It is suggested that intense stimulation of the optic nerve could cause sneezing if the maxillary branch of the trigeminal nerve was stimulated as well as the ophthalmic branch. The theory of parasympathetic generalisation invokes co-activation by one stimulus of neighbouring parasympathetic branches. Light falling on the retina stimulates pupillary constriction (via the third cranial nerve) and lacrimation
  (via the seventh). A stimulus of sufficient intensity could generate
  enough parasympathetic activity to cause nasal congestion and secretions, and
  stimulate sneezing by an effect on the maxillary branch of the trigeminal nerve.
  The theory of parasympathetic hypersensitivity suggests that individuals
  with photic sneezing may have a more active or sensitive parasympathetic system,
  leading to hypersensitive nasal mucosa.


Although what you describe does not involve sneezing I think we can assume the same, or a similar afferent pathway is activated also in that case.

Recent works also found an activation of visual regions of the cortex in response to this stimulus.

From the conclusions of:

When the Sun Prickles Your Nose: An EEG Study Identifying Neural Bases of Photic Sneezing - Langer et al. - PLoS One, 2010


  We propose that the photic sneeze phenomenon might be the consequence of higher sensitivity to visual stimuli in the visual cortex and of co-activation of somatosensory areas. The ‘photic sneeze reflex’ is therefore not a classical reflex that occurs only at a brainstem or spinal cord level but, in stark contrast to many theories, involves also specific cortical areas.