It has been shown that pain impairs cognitive function, in this question and the following studies on the effects of headaches on cognition. Moor et al write
It must therefore be emphasised that headache pain appears to impair general task performance, irrespective of task complexity, rather than specific attentional mechanisms. Headache pain has an effect on the core cognitive components necessary for the successful completion of tasks, and in particular those involving the updating of the cognitive system.
Eccleston et al have shown that the degree to which pain disrupts cognitive processes is related to facts regarding the pain and the individuals psycho-social activities.
The interruptive function of pain depends on the relationship between pain-related characteristics (e.g., the threat value of pain) and the characteristics of the environmental demands (e.g., emotional arousal).
So, it seems that there is physiological and psychological factors that contribute to why pain interferes with cognition.
Are there personality traits that correlate with an individual's ability to cope with pain?
References
- Headache impairs attentional performance. Moore DJ, Keogh E, Eccleston C. Centre for Pain Research, The University of Bath, Bath BA2 7AY, UK.
- Pain demands attention: A cognitive–affective model of the interruptive function of pain. Eccleston, Chris; Crombez, Geert Psychological Bulletin, Vol 125(3), May 1999, 356-366. doi: 10.1037/0033-2909.125.3.356