كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(54)
Chapter: It is recommended to say qunut in all prayers if a calamity befalls the Muslims – and refuge is sought from Allah (regarding that). It is recommended to say qunut in Subh at all times. And the clarification that it is to be said after raising the head from bowing in the final rak`ah, and it is recommended to say it out loud
(54)
باب اسْتِحْبَابِ الْقُنُوتِ فِي جَمِيعِ الصَّلاَةِ إِذَا نزَلَتْ بِالْمُسْلِمِينَ نَازِلَةٌ ‏‏
Sahih Muslim 677 a

Anas b. Malik reported that the Messenger of Allah (ﷺ) invoked curse in the morning (prayer) for thirty days upon those who killed the Companions (of the Holy Prophet) at Bi'r Ma'una. He cursed (the tribes) of Ri'l, Dhakwan, Lihyan, and Usayya, who had disobeyed Allah and His Messenger (ﷺ). Anas said:

Allah the Exalted and Great revealed (a verse) regarding those who were killed at Bi'r Ma'una, and we recited it, till it was abrogated later on (and the verse was like this):, convey to it our people the tidings that we have met our Lord, and He was pleased with us and we were pleased with Him".
وَحَدَّثَنَا يَحْيَى بْنُ يَحْيَى، قَالَ قَرَأْتُ عَلَى مَالِكٍ عَنْ إِسْحَاقَ بْنِ عَبْدِ اللَّهِ بْنِ أَبِي طَلْحَةَ، عَنْ أَنَسِ بْنِ مَالِكٍ، قَالَ دَعَا رَسُولُ اللَّهِ صلى الله عليه وسلم عَلَى الَّذِينَ قَتَلُوا أَصْحَابَ بِئْرِ مَعُونَةَ ثَلاَثِينَ صَبَاحًا يَدْعُو عَلَى رِعْلٍ وَذَكْوَانَ وَلِحْيَانَ وَعُصَيَّةَ عَصَتِ اللَّهَ وَرَسُولَهُ ‏.‏ قَالَ أَنَسٌ أَنْزَلَ اللَّهُ عَزَّ وَجَلَّ فِي الَّذِينَ قُتِلُوا بِبِئْرِ مَعُونَةَ قُرْآنًا قَرَأْنَاهُ حَتَّى نُسِخَ بَعْدُ أَنْ بَلِّغُوا قَوْمَنَا أَنْ قَدْ لَقِينَا رَبَّنَا فَرَضِيَ عَنَّا وَرَضِينَا عَنْهُ ‏.‏
Reference : Sahih Muslim 677a
In-book reference : Book 5, Hadith 378
USC-MSA web (English) reference : Book 4, Hadith 1433
  (deprecated numbering scheme)