Abu Sa'id Khudri reported that during the lifetime of Allah's Messenger (ﷺ) the hypocrites behaved in this way that when Allah's Apostle (ﷺ) set out for a battle, they kept themselves behind, and they became happy that they had managed to sit in the house contrary to (the act of) Allah's Messenger (ﷺ), and when Allah's Apostle (may peace he upon him) came back, they put forward excuses and took oath and wished that people should laud them for the deeds which they had not done. It was on this occasion that this verse was revealed:
" Think not that those who exult in what they have done, and love to be praised for what they have not done-think not them to be safe from the chastisement; and for them is a painful chastisement" (iii. 18).
Reference: Sahih Muslim 2777
In-book reference: Book 51, Hadith 10
USC-MSA web (English) reference(deprecated numbering scheme): Book 38, Hadith 6686