This is known as the Arnold reflex - after the doctor that first described it in 1832. It is fairly rare - around 2 to 4% of the population show this some in both ears others in just one. There is some suggestion that a higher proportion of people might react but not cough - letting out some breath through constriction of the lungs.
The cause of the reflex is the auricular branch of the vagus nerve. I'm not sure how. Perhaps a passing anatomist could shed some light? I presume that some sort of anatomical quirk in some folks puts this nerve in a position where it is stimulated when objects are put in the ear.
Some cases have been reported where ear wax builds up and stimulates this reflex resulting in a persistent cough that leaves doctors puzzled.
Anyway - congratulations! You now have something interesting to talk about at dinner parties. You can even test fellow guests to see if you can discover any other of the 2% - and wow them with your knowledge of the auricular branch of the vagus nerve. Don't overdo it though or folks will just think you are the ear weirdo!