My question might seem odd but it has been wondering in my mind for a bit. When Imam al Mahdi reappears, how will he deal with the women like in his army or like the shia women? Does he have to lower his gaze in their presence? Can he touch them? As in like appropriate way like rubbing his hands on our heads?

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.