Why does my eye hurt when I have a cold?

Many reasons. Some cold infections are caused by viruses that can also directly affect the eye. Usually the eye will be red or have discharge in that case. Colds can lead to inflammation of tissue around the eye, as well as sinus involvement, or blockage of the tear duct. This pressure can result in eye pain. If you have vision change, worse pain, nausea, you should have the eye pain evaluated.
Ethmoid sinusitis. There may be many sources of the eye pain, but the most common cause may be ethmoid sinusitis. The major cause of what we call rhino-sinusitis is viral. The ethmoid sinus has a thin paper plate adjacent to the orbit (eye) and may actually be deshiscent (partially absent). Thus the cold leads to swelling of the mucous membrane of the nose leading to ethmoid sinusitis and irritation of the eye.