Abu `Abdur-Rahman An-Nasa'i recorded that Ibn `Abbas said that they, "Disliked giving charity to their polytheist relatives, but were later on allowed to give it to them when they inquired about this matter, and this Ayah was revealed,
﴿ لَّيۡسَ عَلَيۡكَ هُدَٮٰهُمۡ وَلَـٰڪِنَّ ٱللَّهَ يَهۡدِى مَن يَشَآءُۗ وَمَا تُنفِقُواْ مِنۡ خَيۡرٍ۬ فَلِأَنفُسِڪُمۡۚ وَمَا تُنفِقُونَ إِلَّا ٱبۡتِغَآءَ وَجۡهِ ٱللَّهِۚ وَمَا تُنفِقُواْ مِنۡ خَيۡرٍ۬ يُوَفَّ إِلَيۡڪُمۡ وَأَنتُمۡ لَا تُظۡلَمُونَ ﴾
(Not upon you (Muhammad) is their guidance, but Allah guides whom He wills. And whatever you spend in good, it is for yourselves, when you spend not except seeking Allah's Face. And whatever you spend in good, it will be repaid to you in full, and you shall not be wronged.)
﴿ وَمَا تُنفِقُواْ مِنۡ خَيۡرٍ۬ فَلِأَنفُسِڪُمۡۚ ﴾
(And whatever you spend in good, it is for yourselves) is similar to His other statement,
﴿ مَّنۡ عَمِلَ صَـٰلِحً۬ا فَلِنَفۡسِهِۦۖ ﴾
(Whosoever does righteous good deed, it is for (the benefit of) his own self.)
There are many other similar Ayat in the Qur'an.
﴿ وَمَا تُنفِقُونَ إِلَّا ٱبۡتِغَآءَ وَجۡهِ ٱللَّهِۚ ﴾
(When you spend not except seeking Allah's Face.)
Al-Hasan Al-Basri commented, "Whenever the believer spends, including what he spends on himself, he seeks Allah's Face with it.'' `Ata' Al-Khurasani said that the Ayah means, "You give away charity for the sake of Allah. Therefore, you will not be asked about the deeds )or wickedness( of those who receive it.'' This is a sound meaning indicating that when one spends in charity for Allah's sake, then his reward will be with Allah. He will not be asked if the charity unintentionally reached righteous, evil, deserving or undeserving persons, for he will be rewarded for his good intention. The proof to this statement is the Ayah,
﴿ وَمَا تُنفِقُواْ مِنۡ خَيۡرٍ۬ يُوَفَّ إِلَيۡڪُمۡ وَأَنتُمۡ لَا تُظۡلَمُونَ ﴾
(And whatever you spend in good, it will be repaid to you in full, and you shall not be wronged.)
The Two Sahihs recorded a Hadith by Abu Hurayrah that the Messenger of Allah said,
« قَالَ رَجُلٌ: لَأَتَصَدَّقَنَّ اللَّيْلَةَ بِصَدَقَةٍ، فَخَرجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ زَانِيَةٍ، فَأَصْبَحَ النَّاسُ يَتَحَدَّثُونَ: تُصُدِّقَ عَلَى زَانِيَةٍ، فَقَالَ: اللَّهُمَ لَكَ الْحَمْدُ عَلَى زَانِيَةٍ، لَأَتَصَدَّقَنَّ اللَّيْلَةَ بِصَدَقَةٍ، فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ غَنِيَ، فَأَصْبَحُوا يَتَحَدَّثُونَ: تُصُدِّقَ اللَّيْلَةَ عَلَى غَنِيَ، قَالَ: اللَّهُمَّ لَكَ الْحَمْدُ عَلَى غَنِيَ، لَأَتَصَدَّقَنَّ اللَّيْلَةَ بِصَدَقَةٍ، فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ سَارِقٍ، فَأَصْبَحُوا يَتَحَدَّثُونَ: تُصُدِّقَ اللَّيْلَةَ عَلَى سَارِقٍ، فَقَالَ: اللَّهُمَّ لَكَ الْحَمْدُ عَلَى زَانِيَةٍ، وَعَلَى غَنِيَ، وَعَلَى سَارِقٍ. فَأُتِيَ فَقِيلَ لَهُ: أَمَّا صَدَقَتُكَ فَقَدْ قُبِلَتْ، وَأَمَّا الزَّانِيَةُ فَلَعَلَّهَا أَنْ تَسْتَعِفَّ بِهَا عَنْ زِنَاهَا، وَلَعَلَّ الْغَنِيَّ يَعْتَبِرُ فَيُنْفِقُ مِمَّا أَعْطَاهُ اللهُ، وَلَعَلَّ السَّارِقَ أَنْ يَسْتَعِفَّ بِهَا عَنْ سَرِقَتِه »
(A man said, "Tonight, I shall give charity.'' He went out with his charity and (unknowingly) gave it to an adulteress. The next morning the people said that alms were given to an adulteress. The man said, "O Allah! All the praises are for You. (I gave my alms) to an adulteress. Tonight, I shall give alms again.'' He went out with his charity and (unknowingly) gave it to a rich person. The next morning (the people) said, "Last night, a wealthy person was given alms.'' He said, "O Allah! All the praises are for You. (I gave alms) to a wealthy man. Tonight, I shall again give charity.'' So he went out with his charity and (unknowingly) gave it to a thief. The next morning (the people) said, "Last night, a thief was given alms.'' He said, "O Allah! All the praises are for You. (I have given alms) to an adulteress, a wealthy man and a thief.'' Then, someone came to him and said, "The alms that you gave away were accepted. As for the adulteress, the alms might make her abstain from adultery. As for the wealthy man, it might make him take a lesson and spend his wealth that Allah has given him. As for the thief, it might make him abstain from stealing.'')