I would call this fidgeting.
Fidg·et / ˈfijit/
• v. (fidg·et·ed, fidg·et·ing ) [intr.] make small
movements, esp. of the hands and feet, through nervousness or
impatience: the audience had begun to fidget on their chairs.
• n. a
quick, small movement, typically a repeated one, caused by nervousness
or impatience: he disturbed other people with convulsive fidgets.
- a person given to such movements, esp. one whom other people find
irritating.
- (usu. fidgets) a state of mental or physical
restlessness or uneasiness: a marketing person full of nervous energy
and fidgets.
DERIVATIVES: fidg·et·er n. fidg·et·y adj.
—"fidget." The Oxford Pocket Dictionary of Current English, via Encyclopedia.com. 12 Dec. 2016.
In your sentence,
You could tell Fred was deep in thought because he was tapping his
temple with his finger. He always displays this fidgeting when
lost in thought.
Or
You could tell Fred was deep in thought because he was tapping his
temple with his finger. He always displays this (particular)
fidget when lost in thought.
Examples of fidgeting used for this:
A new study finds that fidgeting — the toe-tapping, foot-wagging
and other body movements that annoy your co-workers — is in fact good
for your health. —Gretchen Reynolds, "Why Fidgeting is Good
Medicine", New York Times, 9/14/2016.
Fidgeting is making small movements with your body, usually your hands and feet. It’s associated with not paying attention.
Fidgeting often reflects discomfort and restlessness. For example, if you’ve been listening to a lecture for a long time, you may find
yourself tapping your pencil. —"What causes fidgeting?"
Healthline.com.
And examples of usage of fidget on its own as a noun for this kind of action (definitely the less common of the two terms):
Nicks started fiddling with the tassels streaming from her mike stand,
an annoying fidget that continued intermittently throughout the
show. —Bill White, "Nicks still casts a musical spell", Seattle
Post-Intelligencer, 8/14/2001.
Tap tap tap tap. Tim Caton taps his pencil on his desk in his hospitality management class. To classmates, it’s an annoying
fidget. But Caton heeds a different beat. —"Life by the Numbers", Vox Magazine, 10/11/2012.
Man, I'm slow! Just noticed that this was suggested in comments while I've been typing. Hat-tip to @stevesliva.