Pain is perceptual and in a good part psychological, because the brain is doing the conversion of a nerve signal into sensation. There's no absolute wiring, it's not an electrical circuit that lights a bulb in proportion to the current. We've all hurt ourselves – perhaps a cut or a bruise – and not notice it until we do notice it and then ouch, thereafter it really hurts. An unnoticed insect bite doesn't itch. Things also hurt at a level we expect them to hurt, even if they're physically the same impact.
Forgetting about a headache is just as effective as any painkiller. If you think a painkiller won't work, it probably won't. If you tell someone that something will hurt more, it will hurt more. If you tell them it won't hurt, it probably will, because they won't believe you.
It ties into sensory hypervigilance, where a person focuses on something, and the more they focus, the more they notice and feel. Generally, for instance, unless they're uncomfortable, you don't feel your clothes. Or rather you do, but your brain elides what it considers to be not a very useful qualia. But it you put some effort into feeling your clothes you can. That can become pathological when you really start to focus on something, become hypervigilant, start obsessing on a sensation. Pain is the same, a little itch or ache, can grow to serious, chronic pain that is generally only temporarily relieved with even the strongest painkillers.
There's a good, strong theory that a lot of psychogenic issues are, to a degree, caused by sensory hypervigilance. If you're constantly assessing how tired you feel, it's no surprise you come up feeling tired a lot, chronically fatigued in fact. If you're forever wondering about bowel activities, wondering about every rumble, then yes, it does seem to be irritable. Those are longer-term issues, like chronic pain, but it's still the power of the mind.
Of course, it goes the other way, where people can either convince themselves or be convinced (by hypnosis) to undergo radical surgery – up to and including limb amputation – without anaesthetic and state that they felt no pain during or after the procedure.