Shaking Hands with Non-Mahram Women
Question

I would like a detailed answer on the ruling on a man shaking hands with a woman, and the views of the four imams and the majority of scholars on that.
Praise be to Allah.Shaking hands with non-Mahram women
It is not permissible for a man who believes in Allah and His Messenger to put his hand in the hand of a woman who is not permissible for him or who is not one of his Mahrams. Whoever does that has wronged himself (i.e., sinned).
It was narrated that Ma`qil ibn Yassar (may Allah be pleased with him) said: the Messenger of Allah (peace and blessings of Allah be upon him) said: “For one of you to be stabbed in the head with an iron needle is better for him than that he should touch a woman who is not permissible for him.”  (Narrated by At-Tabarani in Al-Kabir, 486. Shaykh Al-Albani classed it as authentic in Sahih Al-Jami`, 5045.)
This Hadith alone is sufficient to deter and to instil the obedience required of us by Allah, because it implies that touching women may lead to temptation and immorality.
It was narrated that `A’ishah (may Allah be pleased with her) the wife of the Prophet (peace and blessings of Allah be upon him) said: “When the believing women migrated to the Messenger of Allah (peace and blessings of Allah be upon him), they would be tested in accordance with the words of Allah (interpretation of the meaning):
{O Prophet! When believing women come to you to give you the Bay`ah (pledge), that they will not associate anything in worship with Allah, that they will not steal, that they will not commit illegal sexual intercourse} [Al-Mumtahanah 60:12]
`A’ishah said: Whoever among the believing women agreed to that had passed the test, and when the women agreed to that, the Messenger of Allah (peace and blessings of Allah be upon him) said to them: “Go, for you have given your oath of allegiance.` No, by Allah, the hand of the Messenger of Allah (peace and blessings of Allah be upon him) never touched the hand of any woman, rather they would give their oath of allegiance with words only.” And `A’ishah said: “By Allah, the Messenger of Allah (peace and blessings of Allah be upon him) only took the oath of allegiance from the women in the manner prescribed by Allah, and the hand of the Messenger of Allah (peace and blessings of Allah be upon him) never touched the hand of any woman. When he had taken their oath of allegiance he would say, `I have accepted your oath of allegiance verbally.`” (Narrated by Muslim, 1866)
It was narrated from `Urwah that `A’ishah told him about the women’s oath of allegiance: “The Messenger of Allah (peace and blessings of Allah be upon him) never touched any woman with his hand. He would explain to the woman what the oath of allegiance implied, and when she accepted, he would say ‘Go, for you have given your oath of allegiance.’”  (Narrated by Muslim, 1866)
This infallible one, the best of mankind, the leader of the sons of Adam on the Day of Resurrection, did not touch women. This is despite the fact that the oath of allegiance was originally given by hand. So how about men other than the Prophet (peace and blessings of Allah be upon him)?
It was narrated that Umaymah the daughter of Raqiqah said: The Messenger of Allah (peace and blessings of Allah be upon him) said, “I do not shake hands with women.” (Narrated by An-Nasa`i, 4181 and Ibn Majah, 2874; classed as authentic by Al-Albani in Sahih Al-Jami`, 2513)
Can you shake hands with non-Mahram women with a barrier in between?
It is not permissible to shake hands even with a barrier in between, such as shaking hands from beneath a garment and the like. The Hadith that was narrated allowing that is inauthentic.
It was narrated from Ma`qal ibn Yassar that the Prophet (peace and blessings of Allah be upon him) used to shake hands with women from beneath a garment.” (Narrated by At-Tabarani in Al-Awsat, 2855)
Al-Haythami (may Allah have mercy on him) said:
“This was narrated by At-Tabarani in Al-Kabir and Al-Awsat. Its chain of narration includes `Atab ibn Harb, who is weak.” (Majma` Al-Zawa`id, 6/39)
Wali Ad-Din Al-`Iraqi said:
“The words of `A’ishah, “He used to accept the women’s oath of allegiance by words only” mean that he did so without taking their hands or shaking hands with them. This indicates that the Bay`ah of men was accepted by taking their hands and shaking hands with them, as well as by words, and this is how it was.  What `A’ishah mentioned was the custom.
Some of the commentators of the Quran mentioned that the Prophet (peace and blessings of Allah be upon him) called for a vessel of water and dipped his hand in it, then the women dipped their hands in it. And some of them said that he did not shake hands with them from behind a barrier and had a Qatari cloak over his hand. And it was said that `Umar (may Allah be pleased with him) shook hands with them on his behalf. None of these reports are sound, especially the last one, “How could `Umar (may Allah be pleased with him) have done something that the Prophet (peace and blessings of Allah be upon him), who was Ma`sum (infallible), would not do?” (End quote from Tarh At-Tathrib, 7/45)
Shaykh Ibn Baz (may Allah have mercy on him) said:
The most correct view is that this (i.e., shaking hands with women from behind a barrier) is not allowed at all, because of the general meaning of the Hadith, according to which the Prophet (peace and blessings of Allah be upon him) said, “I do not shake hands with women;” and so as to ward off the means that may lead to evil. (Adapted from Hashiyat Majmu`at Rasa`il fi`l-Hijab was-Sufur, p. 69)
Can men shake hands with old women?
The same ruling applies to shaking hands with old women; this is also prohibited because of the general meaning of the texts on this issue. The reports that say it is permissible are inauthentic.
Al-Zayla`i (may Allah have mercy on him) said:
“As for the report that Abu Bakr used to shake hands with old women, it is also inauthentic.” (Nasab Ar-Rayah, 4/240)
Ibn Hajar (may Allah have mercy on him) said:
“I cannot find this Hadith.” (End quote from Ad-Dirayah fi Takhrij Ahadith Al-Hidayah, 2/225)
Views of the four imams on shaking hands with non-Mahram women
With regard to the views of the four imams, they are as follows:

The Hanafi Madhhab:

Ibn Nujaym (may Allah have mercy on him) said:
“It is not permissible for a man to touch a woman’s face or hands even if there is no risk of desire because it is prohibited in principle and there is no necessity that would allow it.”  (End quote from Al-Bahr Al-Ra’iq, 8/219)

The Maliki Madhhab:

Muhammad ibn Ahmad (`Ulaysh) (may Allah have mercy on him) said:
“It is not permissible for a man to touch the face or hand of a non-Mahram woman, and it is not permissible for him to put his hand on hers without a barrier. `A’ishah (may Allah be pleased with her) said: “The Prophet (peace and blessings of Allah be upon him) never accepted a woman`s oath of allegiance by shaking hands with her; rather he (peace and blessings of Allah be upon him) used to accept their oath of allegiance by words only.” According to another report, “His hand never touched the hand of a woman, rather he would accept their oath of allegiance by words only.”  (End quote from Minah Al-Jalil Sharh Mukhtasar Khalil, 1/223)

The Shafa`i Madhhab:

An-Nawawi (may Allah have mercy on him) said:
“It is not permissible to touch a woman in any way.” (End quote from Al-Majmu`, 4/515)
Wali Ad-Din Al-`Iraqi (may Allah have mercy on him) said:
“This indicates that the hand of the Prophet (peace and blessings of Allah be upon him) did not touch the hand of any woman apart from his wives and concubines, whether in the case of accepting the oath of allegiance or in other cases. If he did not do that despite the fact that he was infallible and beyond suspicion, then it is even more essential that others heed this prohibition. It appears from the texts that he refrained from doing that because it was prohibited for him to do so. The jurists  among our companions and others said that it is prohibited to touch a non-Mahram woman even if that is not touching parts of her body that are not `Awrah, such as her face. But they differed with regard to looking when there is no desire and no fear of Fitnah. The prohibition on touching is stronger than the prohibition on looking, and it is prohibited when there is no necessity that would allow it. If it is the case of necessity, e.g. medical treatment, removing a tooth or treating the eyes, etc., if there is no woman who can do that, then it is permissible for a non-Mahram to do that because it is the case of necessity.” (End quote from Tarh At-Tathrib, 7/45, 46)

The Hanbali Madhhab

Ibn Muflih (may Allah have mercy on him) said:
“Abu `Abdullah – i.e., Imam Ahmad – was asked about a man who shakes hands with a woman. He said, No, and was emphatic that it is prohibited. I said, “Should he shake hands with her from beneath his garment?” He said, “No.”
Shaykh Taqiy Ad-Din also favoured the view that it is prohibited, and gave the reason that touching is more serious than looking.” (End quote from Al-Adab As-Shar`iyyah, 2/257)
And Allah knows best.