Sunan an-Nasa'i, Volume 3, Book 23, Hadith 2524 (DarusSalam)

Abu Hurairah narrated that the Messenger of Allah said: "A man said" 'I am going to give some charity.' So he went out with his charity and put it in the hand of a thief. The next morning they started talking about how charity had been given to a thief. Then he said: 'O Allah, to You be praise for the thief. I am going to give some charity.' So he went out with his charity and put it in the hand of a prostitute. The next morning they started talking about how charity had been given to a prostitute. He said: 'O Allah, to You be praise for the prostitute. I am going to give some charity. So he went out with his charity and put it in the hand of a rich man. The next morning they started talking about how charity had been given to a rich man. He said: 'O Allah, th You be praise for the prostitute, the thief and the rich man. 'Then the message came to him: As for your charity, it is accepted. As for the prostitute, perhaps it will keep her from committing Zina. As for the thief, perhaps it will stop him from stealing. And as for the rich man, perhaps he will learn a lesson, and will spend from that which Allah, the Mighty and Sublime, has given him."'

أَخْبَرَنَا عِمْرَانُ بْنُ بَكَّارٍ، قَالَ حَدَّثَنَا عَلِيُّ بْنُ عَيَّاشٍ، قَالَ حَدَّثَنَا شُعَيْبٌ، قَالَ حَدَّثَنِي أَبُو الزِّنَادِ، مِمَّا حَدَّثَهُ عَبْدُ الرَّحْمَنِ الأَعْرَجُ، مِمَّا ذَكَرَ أَنَّهُ سَمِعَ أَبَا هُرَيْرَةَ، يُحَدِّثُ بِهِ عَنْ رَسُولِ اللَّهِ صلى الله عليه وسلم وَقَالَ ‏ "‏ قَالَ رَجُلٌ لأَتَصَدَّقَنَّ بِصَدَقَةٍ فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ سَارِقٍ فَأَصْبَحُوا يَتَحَدَّثُونَ تُصُدِّقَ عَلَى سَارِقٍ فَقَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى سَارِقٍ لأَتَصَدَّقَنَّ بِصَدَقَةٍ فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ زَانِيَةٍ فَأَصْبَحُوا يَتَحَدَّثُونَ تُصُدِّقَ اللَّيْلَةَ عَلَى زَانِيَةٍ فَقَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى زَانِيَةٍ لأَتَصَدَّقَنَّ بِصَدَقَةٍ فَخَرَجَ بِصَدَقَتِهِ فَوَضَعَهَا فِي يَدِ غَنِيٍّ فَأَصْبَحُوا يَتَحَدَّثُونَ تُصُدِّقَ عَلَى غَنِيٍّ قَالَ اللَّهُمَّ لَكَ الْحَمْدُ عَلَى زَانِيَةٍ وَعَلَى سَارِقٍ وَعَلَى غَنِيٍّ فَأُتِيَ فَقِيلَ لَهُ أَمَّا صَدَقَتُكَ فَقَدْ تُقُبِّلَتْ أَمَّا الزَّانِيَةُ فَلَعَلَّهَا أَنْ تَسْتَعِفَّ بِهِ مِنْ زِنَاهَا وَلَعَلَّ السَّارِقَ أَنْ يَسْتَعِفَّ بِهِ عَنْ سَرِقَتِهِ وَلَعَلَّ الْغَنِيَّ أَنْ يَعْتَبِرَ فَيُنْفِقَ مِمَّا أَعْطَاهُ اللَّهُ عَزَّ وَجَلَّ ‏" ‏ ‏.‏

sunnah.com