This is a remarkably common problem, especially among the young. The muscles that allow you to chew (muscles of mastication) can be overworked and strained, the same as any other muscle in your body. If the muscles are well-toned, not weak, and not overworked/strained, this will not be a problem. BUT, if you chew gum a lot, especially if you have a lot of tension in the muscles of mastication anyways, you're going to have problems...
The muscles that make the motion/act of chewing/clenching include the masseter, lateral/medial pterygoids, and the temporalis.
In the case of headache resulting from chewing gum, or any painful chewing, your culprit will most likely be the muscle temporalis. (Areas of red denote painful zones; the 'x's are where myofascial trigger points are most likely to be, and to search for "muscle knots" to compress and massage out. See:
A trigger point can often be "deactivated" by simple heating, compression(1-2 minutes on the "x"), and stretching the muscle.
(temporalis trigger points; )
(wiki) These areas have many common nerve roots and feedback mechanisms in sensorimotor pathways.
If you put your fingers on your temples near the ear, then clench your jaw, you will feel this muscle contract, although not as strongly as masseter, the primary muscle of jaw flexion. Temporalis, and all muscles of mastication and jaw movement, are some of the strongest (force-per-mass) muscles of the body, and get the most workout. My old anatomy/physiology teacher loved the biology joke of how there a lesson behind the fact that there is one major muscle to open the mouth, yet four to close it!
The easiest way to avoid activating the pain is, obviously, avoid chewing gum. But, if regular chewing becomes a problem, these self-care techniques can be tried more often. If there is a major bite malocclusion (misplacement between upper and lower teeth), it will still occur, though, and it will need to be seen to and corrected by an orthodontist.