Even though he is an infallible Imam, he will uphold Islamic laws. Hence, he will not touch non-Mahram women or see them without or fix his gaze at them. Yes he will pray for them and bless them, but not touch them physically. As for the hadih that says he will place his hands on the heads of people:
1- It might be symbolic, meaning you will pray for people’s intellect to be completed, or hr will give people a healthy system that completes their intellect
2- Or he might do that over the hijab/scarf, not directly touch their hair.