Hmm i am curious too, however I'm no expert on these matters but iirc I did read that to save a life or to administer emergency first aid then it's ok for even non Mahram to put their hands on a person (just to the extent necessary, and in the absence of a same gender helper or mahram ).
If a female expert is not available, neither is there a female who can be instructed to treat her… then in such a case it would be permitted for a male doctor to treat her, provided there is a genuine need. It will be necessary for her to cover other than the effected area, and he must lower his gaze as much as possible.” (al-Fatawa al-Hindiyya, 5/330)
https://islamqa.org/hanafi/daruliftaa/7945