Abu Hurairah reported,

The Messenger of Allah ﷺ said, "A man said, 'I will surely give a charity tonight.' So he went out with his charity and placed it in the hand of a thief. The next morning people were talking, saying, 'Charity was given to a thief last night!'He said, 'O Allah, to You belongs all praise. I will surely give a charity.' So he went out with his charity and placed it in the hands of a prostitute. The next morning people were talking, saying, 'Charity was given to a prostitute last night!'He said, 'O Allah, to You belongs all praise, even for a prostitute. I will surely give a charity.' So he went out with his charity and placed it in the hands of a wealthy man. The next morning people were talking, saying, 'Charity was given to a wealthy man!'He said, 'O Allah, to You belongs all praise, for a thief, for a prostitute, and for a wealthy man.'Then he was approached and told, 'As for your charity to the thief, perhaps it will cause him to refrain from his stealing. As for the prostitute, perhaps it will cause her to refrain from her fornication. As for the wealthy man, perhaps he will take heed and spend from what Allah has given him.'"

Azami 4131

Sahih

عن أبي هريرة

أن رسول الله ﷺ قال: قال رجل: لأتصدقن بصدقة فخرج بصدقته فوضعها في يد سارق، فأصبحوا يتحدثون تصدق على سارق! فقال: اللهم لك الحمد، لأتصدقن بصدقة فخرج بصدقته فوضعها في يدي زانية، فأصبحوا يتحدثون تصدق الليلة على زانية! فقال: اللهم لك الحمد على زانية، لأتصدقن بصدقة فخرج بصدقته فوضعها في يدي غني، فأصبحوا يتحدثون تصدق على غني! فقال: اللهم لك الحمد على سارق، وعلى زانية، وعلى غني، فأتي فقيل له أما صدقتك على سارق فلعله أن يستعف عن سرقته، وأما الزانية فلعلها أن تستعف عن زناها، وأما الغني فلعله يعتبر فينفق مما أعطاه الله.

الأعظمي 4131صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Zakat
Chapter
Encouragement to pay zakat and charity and the ways of spending them
Section
Reward of the one who gives charity even if it ends up in the hands of someone undeserving
Numbering
Jami al-Kamil 4131 (2nd edition)
Azami 4131