When a person remembers something, he concentrates all his attention on the thought process. He can even raise his eyes to the top or close them. And when all attention is concentrated in the upper body, then any irritants in the form of an itchy head must be eliminated so as not to distract from the mental process. Also, when you think to the head there is a large flow of blood with oxygen, thus creating discomfort. While writing this, 20 times I scratched my head))
Psychological gesture. To be honest, this is not always the case, if a person scratches his head, it means he is trying to remember something.
It is also a gesture of doubt, uncertainty, an abstract gesture. This is an opportunity to give yourself time to think.