A man entered the mosque on Friday while the Messenger of Allah ﷺ was delivering the sermon, and he said to him, "Pray two rakahs."Then he came the following Friday while the Prophet ﷺ was delivering the sermon, and he said to him, "Pray two rakahs."Then he came the third Friday, and he said, "Pray two rakahs."Then he said, "Give in charity," so the people gave in charity, and he handed the man two garments.Then he said, "Give in charity," and the man tossed down one of his two garments.The Messenger of Allah ﷺ said, "Did you not see this man? He entered the mosque in a shabby state, and I hoped you would notice him and give him charity, but you did not. So I said, 'Give in charity,' and you gave, and I handed him two garments. Then I said, 'Give in charity,' and he threw down one of his two garments. Take your garment back!" And he rebuked him.
أخبرنا عمرو بن علي قال حدثنا يحيى قال حدثنا ابن عجلان عن عياض
أن رجلا دخل المسجد يوم الجمعة ورسول الله ﷺ يخطب فقال صل ركعتين ثم جاء الجمعة الثانية والنبي ﷺ يخطب فقال صل ركعتين ثم جاء الجمعة الثالثة فقال صل ركعتين ثم قال تصدقوا فتصدقوا فأعطاه ثوبين ثم قال تصدقوا فطرح أحد ثوبيه فقال رسول الله ﷺ ألم تروا إلى هذا أنه دخل المسجد بهيئة بذة فرجوت أن تفطنوا له فتتصدقوا عليه فلم تفعلوا فقلت تصدقوا فتصدقتم فأعطيته ثوبين ثم قلت تصدقوا فطرح أحد ثوبيه خذ ثوبك وانتهره
[Its chain of transmission is hasan] Abu Dawud reported it in Zakat, chapter "A man who gives away his entire wealth," no. 1675, and Tirmidhi in Prayer, chapter "What has been mentioned regarding the two rakahs when a man enters while the imam is delivering the sermon," no. 511, from the hadith of Ibn Ajlan, with the same wording, and he explicitly stated hearing it directly in Humaydi's version, no. 741, and it is also found in al-Kubra, no. 2316. Tirmidhi said, "Hasan sahih."