Opposite sex includes 2 categories: mahram and non-mahram. For a man or a woman to shake hands with the opposite gender that is not his/her mahram is not permitted at all. The evidence for this can be found in this hadith:
Ma’qal ibn Yassaar (may Allaah be pleased with him) who said: “The Messenger of Allaah (peace and blessings of Allaah be upon him) said: ‘If one of you were to be struck in the head with an iron needle, it would be better for him than if he were to touch a woman he is not allowed to.” (Reported by al-Tabaraani; classed as saheeh by al-Albaani in Saheeh al-Jaami’, 5045).
One cannot argue that for a man to touch a non mahram woman is one of the causes of fitnah, the temptation and the turmoil. It provokes the desire and promotes committing haraam deeds.
Anybody saying that their intention is sound and their heart is clean should not say that because the one with the purest of all hearts and the most chaste of all, the messenger of Allah(peace be upon him) never touched a non mahram woman even when accepting bayah(oath of allegiance) from women. He never held their hands, their words were enough for them, although he would hold hands of men when taking bayah from them, as was reported by his wife ‘Aa’ishah (may Allaah be pleased with her).
She said that the Messenger of Allaah (peace and blessings of Allaah be upon him) would test the believing women who emigrated to him with the aayah (interpretation of the meaning): “O Prophet! When believeing women come to you to give you the bay’ah (pledge), that they will not associate anything in worship with Allaah, that they will not steal, that they will not commit illegal sexual intercourse, that they will not kill their children, that they will not utter slander, intentionally forging falsehood (i.e., by making illegal children belong to their husbands), and that thye will not disobey you in any ma’ruf (Islamic monotheism and all that which Islam ordains), then accept their bay’ah and ask Allaah to forgive them. Verily Allaah is Oft-Forgiving, Most Merciful.”
[al-Mumtahinah 60:12] ‘Aa’ishah said: “So whoever of the believing women agreed to these conditions, the Messenger of Allaah (peace and blessings of Allaah be upon him) would say to her: ‘I have accepted your bay’ah by words.’ By Allaah, his hand never touched the hand of any woman when accepting their bay’ah; he accepted their bay’ahby saying ‘I have accepted your bay’ah on this basis.’”
(Reported by al-Bukhaari, 4512; according to another report: he accepted their bay’ah by words… the hand of the Messenger of Allaah (peace and blessings of Allaah be upon him) never touched the hand of any woman except a woman he owned . Reported by al-Bukhaari, 6674).
Some Muslims feel too embarrassed to refuse the non mahram to shake hands with them. In addition to mixing with women, some of them claim that they are forced to shake hands with fellow-students and teachers in schools and universities, or with colleagues in the workplace, or in business meetings and so on, but this is not an acceptable excuse.
A Muslim should be strong in his faith, he should overcome his own feelings and the promptings of the Shaytaan. Being a Muslim, you must apologize politely and explain the reason behind your action. Speak up that it is not to offend them or hurt them but to protect your belief. In most cases, this will earn him respect from others. There is no harm done if they find it strange at first, and it may even be a practical opportunity for da’wah.
And Allaah knows best.
MY Allah protect us all.