Some men from among the hypocrites during the time of the Messenger of Allah ﷺ used to stay behind whenever the Prophet ﷺ set out for battle, rejoicing at remaining behind in opposition to the Messenger of Allah ﷺ. When the Prophet ﷺ returned, they would offer him excuses and swear oaths, wishing to be praised for what they had not done. So the verse was revealed, "Do not think that those who rejoice in what they have done and love to be praised for what they have not done, do not think them to be safe from punishment" [Aal Imran 3:188].
حدثنا الحسن بن علي الحلواني ومحمد بن سهل التميمي قالا حدثنا ابن أبي مريم أخبرنا محمد بن جعفر أخبرني زيد بن أسلم عن عطاء بن يسار
أن رجالا من المنافقين في عهد رسول الله ﷺ كانوا إذا خرج النبي ﷺ إلى الغزو تخلفوا عنه وفرحوا بمقعدهم خلاف رسول الله ﷺ فإذا قدم النبي ﷺ اعتذروا إليه وحلفوا وأحبوا أن يحمدوا بما لم يفعلوا فنزلت {لا تحسبن الذين يفرحون بما أتوا ويحبون أن يحمدوا بما لم يفعلوا فلا تحسبنهم بمفازة من العذاب}