Assalamualaikum ustaz. Is it sinful if I accidentally touches the hand of a non-mahram, such as when I was passing something? Next, will it invalidate my ablution, even if it is unintentional? Hope for an explanation.
Waalaikumussalam wrt. wbt.,
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
We start with Allah SWT’s statement:
رَبَّنَا لَا تُؤَاخِذْنَا إِن نَّسِينَا أَوْ أَخْطَأْنَا
“Our Lord, do not impose blame upon us if we have forgotten or erred.” 
Al-Syaukani when commenting on this verse said, there is a hadith where the companions supplicated with this supplication and Allah SWT answered: “Yes, indeed I’ll do that.” Hence, the unintentional sin or sins they commit due to forgetfulness are lifted. Hence, there isn’t any khilaf that the lifted sins (forgiven) for two situations which are when one forgets and mistaken (unintentional). 
The ruling of physical contact between man and woman
Basically, skin contact between an adult ajnabi man and woman is prohibited. In a hadith from Ma‘qil bin Yasar R.A, he said Rasullullah PBUH said:
لأَنْ يُطْعَنَ فِي رَأْسِ أَحَدِكُمْ بِمِخْيَطِ مِنْ حَدِيدٍ خَيرٌ لَهُ مِنْ أَنْ يَمَسَّ امْرَأةً لَا تَحِلُّ لَهُ
“If one of your heads is stabbed with an iron needle, it is better for him compared to him touching a woman who isn’t permissible for him (non-mahram).” 
The above hadith clearly shows the prohibition against skin contact between a non-mahram man and woman. Although the literal meaning from the hadith shows the prohibition on man, however, the ruling applies on a woman against touching a man impermissible for her. Regarding this matter, al-Khattabi said:
الْخِطَاب إِذَا وَرَدَ بِلَفْظِ الذُّكُورِ كَانَ خِطَابًا لِلنِّسَاءِ إِلَّا فِي مَوَاضِعَ مَخْصُوصَةٍ
“A khitab (nas/evidence) when the male phrase is used, hence, it is also for (applicable) for female, except in certain situations.” 
Likewise, physical contact between an adult ajnabi man and woman without anything in between them is included in matters that invalidate ablution, regardless of whether it is intentional or otherwise. 
In al-Fiqh al-Manhaji, it is stated that among the matters that invalidate an ablution is a man touching his wife or other women (ajnabi) without anything between them (lining). The act invalidates both their ablutions. The meaning of other women (ajnabi) is every woman that is permissible for the man to marry. This is in accordance with the statement of Allah SWT in explaining the matters that obligate ablution:
أَوْ لَامَسْتُمُ النِّسَاءَ
“…or you have contacted women,” 
According to the mutawatir recitation, the word “لَامَسْتُمُ” means “لَمَسْتُم”, which means you touching her. 
Thus, if one accidentally touches his wife invalidating his ablution, then surely this is so other ajnabi woman’s skin.
Coming back to the above-presented question, an unintentional act is categorized as al-Khata’ which is a mistake, which is usually used to show something is the opposite of “intentional”. This is as stated in the statement of Allah SWT:
وَلَيْسَ عَلَيْكُمْ جُنَاحٌ فِيمَا أَخْطَأْتُم بِهِ وَلَكِن مَّا تَعَمَّدَتْ قُلُوبُكُمْ
“And there is no blame upon you for that in which you have erred but [only for] what your hearts intended.” 
The above verse means that one isn’t considered sinful due to a transgression that happens unintentionally, however, Allah SWT will consider – it as a sin – if you did the action or matter intentionally. 
Moreover, there is a narration from Ibn Abbas R.Anhuma, where Rasullullah PBUH said:
إنَّ اللهَ تعالى وضع عن أُمَّتي الخطأَ، والنسيانَ، وما اسْتُكرِهوا عليه
“Allah, the Most High, has overlooked my follower’s mistakes and forgetfulness, and what they are forced to do against their will.” 
Both the above evidences show that an act done unintentionally or by mistake isn’t considered a sin.
This matter is strengthened with the statement from Ibn Rajab al-Hanbali when commenting on this hadith – the clearest according to him – a person who forgets or mistaken is forgiven. In other words, sin is lifted from both of them, for sin is based on purpose and intention. While a person who forgets and is mistaken, both don’t intend to do it, then they aren’t considered sinful. As for the ruling isn’t applicable for both of them isn’t the meaning from this evidence. Thus, to sabit and denies it needs for another evidence. 
Based on the above discussion and deliberations, in our opinion, unintentional physical contact between non-mahram man and woman isn’t sinful, however, the contact that causes the ablution of them both is invalidate if there is no lining between them even if it is unintentional.
May Allah SWT grant us all a clear understanding in religion. Amin.
 Surah al-Baqarah: 286
 See Zubdah al-Tafasir min Fath al-Qadir by al-Asyqar, pg. 62.
 Narrated by al-Tabarani (486); Narrated by al-Ruyani in his musnad (1283)
 See Mirqah al-Mafatih, 2/423.
 See Al-Taqrirat al-Sadidah, pg. 100-103; al-Mujtaba fi Syarh Safinah al-Naja, pg. 38.
 Surah al-Ma’idah: 6
 See al-Fiqh al-Manhaji, 1/63.
 Surah al-Ahzab: 5
 See Tafsir al-Muyassar, pg. 418.
 Narrated by Ibn Majah (2045); Narrated by al-Tabarani in al-Mu‘jam al-Ausat (8273); Narrated by al-Baihaqi (11787)
 See Jami‘ al-‘Ulum wa al-Hikam, 2/369.