Jami` at-Tirmidhi, Book 47, Hadith 3327 (In-Book)

Narrated Al-Bara: "A man among the Companions of the Prophet died before Khamr had been made unlawful. So when Khamr was made unlawful, some men said: 'How about our companions who died while drinking Khamr?' So (the following) was revealed: Those who believe and do righteous good deeds, there is no sin on them for what the ate, if they have Taqwa and perform good (5:93)."

حَدَّثَنَا عَبْدُ بْنُ حُمَيْدٍ، حَدَّثَنَا عُبَيْدُ اللَّهِ بْنُ مُوسَى، عَنْ إِسْرَائِيلَ، عَنْ أَبِي إِسْحَاقَ، عَنِ الْبَرَاءِ، قَالَ مَاتَ رِجَالٌ مِنْ أَصْحَابِ النَّبِيِّ صلى الله عليه وسلم قَبْلَ أَنْ تُحَرَّمَ الْخَمْرُ فَلَمَّا حُرِّمَتِ الْخَمْرُ قَالَ رِجَالٌ كَيْفَ بِأَصْحَابِنَا وَقَدْ مَاتُوا يَشْرَبُونَ الْخَمْرَ فَنَزَلَتْ ‏:‏ ‏(‏ لَيْسَ عَلَى الَّذِينَ آمَنُوا وَعَمِلُوا الصَّالِحَاتِ جُنَاحٌ فِيمَا طَعِمُوا إِذَا مَا اتَّقَوْا وَآمَنُوا وَعَمِلُوا الصَّالِحَاتِ ‏)‏ ‏.‏ قَالَ أَبُو عِيسَى هَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ ‏.‏

sunnah.com