Hadithcore
Mishkat al-Masabih, 1611

‘Ubaidallah b Khalid reported God’s messenger as saying, “Sudden death is an act of punishment out of anger.” Abu Dawud transmitted it. Baihaqi in <i>Shu'ab al-iman</i> and Razin in his book made an addition, saying “An act of punishment out of anger for the infidel and a mercy for the believer.”

وَعَنْ عُبَيْدِ اللَّهِ بْنِ خَالِدٍ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «مَوْتُ الْفُجَاءَة أَخْذَةُ الْأَسَفِ» . رَوَاهُ أَبُو دَاوُدَ وَزَادَ الْبَيْهَقِيُّ فِي شُعَبِ الْإِيمَانِ وَرَزِينٌ فِي كِتَابِهِ: «أَخْذَةُ الأسف للْكَافِرِ وَرَحْمَة لِلْمُؤمنِ»

References1 variant
In-Book Reference
Book 5, Hadith 87