Answer:
In simple terms, your headache is the main area that is your brain is stimulating the pain. When you are distracting your brain from the headache by pinching your leg, your brain is kind of "forgetting" the headache for a second by the pain in your leg.