Sahih Muslim , Book 38, Hadith 6686 (USC-MSA)

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).

حَدَّثَنَا الْحَسَنُ بْنُ عَلِيٍّ الْحُلْوَانِيُّ، وَمُحَمَّدُ بْنُ سَهْلٍ التَّمِيمِيُّ، قَالاَ حَدَّثَنَا ابْنُ أَبِي، مَرْيَمَ أَخْبَرَنَا مُحَمَّدُ بْنُ جَعْفَرٍ، أَخْبَرَنِي زَيْدُ بْنُ أَسْلَمَ، عَنْ عَطَاءِ بْنِ يَسَارٍ، عَنْ أَبِي سَعِيدٍ، الْخُدْرِيِّ أَنَّ رِجَالاً، مِنَ الْمُنَافِقِينَ فِي عَهْدِ رَسُولِ اللَّهِ صلى الله عليه وسلم كَانُوا إِذَا خَرَجَ النَّبِيُّ صلى الله عليه وسلم إِلَى الْغَزْوِ تَخَلَّفُوا عَنْهُ وَفَرِحُوا بِمَقْعَدِهِمْ خِلاَفَ رَسُولِ اللَّهِ صلى الله عليه وسلم فَإِذَا قَدِمَ النَّبِيُّ صلى الله عليه وسلم اعْتَذَرُوا إِلَيْهِ وَحَلَفُوا وَأَحَبُّوا أَنْ يُحْمَدُوا بِمَا لَمْ يَفْعَلُوا فَنَزَلَتْ ‏{‏ لاَ تَحْسَبَنَّ الَّذِينَ يَفْرَحُونَ بِمَا أَتَوْا وَيُحِبُّونَ أَنْ يُحْمَدُوا بِمَا لَمْ يَفْعَلُوا فَلاَ تَحْسَبَنَّهُمْ بِمَفَازَةٍ مِنَ الْعَذَابِ‏}‏

sunnah.com