Bulugh al-Maram 330
وَعَنِ ابْنِ مَسْعُودٍ - رضي الله عنه - قَالَ: صَلَّى رَسُولُ اللَّهِ - صلى الله عليه وسلم - فَلَمَّا سَلَّمَ ⦗١٠٠⦘ قِيلَ لَهُ: يَا رَسُولَ اللَّهِ, أَحَدَثَ فِي الصَّلَاةِ شَيْءٌ? قَالَ: «وَمَا ذَلِكَ?». قَالُوا: صَلَّيْتَ كَذَا, قَالَ: فَثَنَى رِجْلَيْهِ وَاسْتَقْبَلَ الْقِبْلَةَ, فَسَجَدَ سَجْدَتَيْنِ, ثُمَّ سَلَّمَ, ثُمَّ أَقْبَلَ عَلَيْنَا بِوَجْهِهِ فَقَالَ: «إِنَّهُ لَوْ حَدَثَ فِي الصَّلَاةِ شَيْءٌ أَنْبَأْتُكُمْ بِهِ, وَلَكِنْ إِنَّمَا أَنَا بَشَرٌ أَنْسَى كَمَا تَنْسَوْنَ, فَإِذَا نَسِيتُ فَذَكِّرُونِي, وَإِذَا شَكَّ أَحَدُكُمْ فِي صَلَاتِهِ فَلْيَتَحَرَّ الصَّوَابَ, فلْيُتِمَّ عَلَيْهِ, ثُمَّ لِيَسْجُدْ سَجْدَتَيْنِ». مُتَّفَقٌ عَلَيْهِ. وَفِي رِوَايَةٍ لِلْبُخَارِيِّ: «فَلْيُتِمَّ, ثُمَّ يُسَلِّمْ, ثُمَّ يَسْجُدْ». وَلِمُسْلِمٍ: أَنَّ النَّبِيَّ - صلى الله عليه وسلم - سَجَدَ سَجْدَتَيْ السَّهْوِ بَعْدَ السَّلَامِ وَالْكَلَامِ.
Ibn Masʿud, may Allah be pleased with him, said: The Messenger of Allah ﷺ prayed, and when he gave salam it was said to him: "O Messenger of Allah, has something new happened regarding the prayer?" He said: "And what is that?" They said: "You prayed such-and-such." He said: So he folded his legs, faced the qiblah, prostrated twice, then gave salam. Then he turned his face towards us and said: "If something new had happened regarding the prayer, I would have informed you of it. But I am only a human being; I forget as you forget. So when I forget, remind me. And when one of you is in doubt in his prayer, let him aim for what is correct and complete [his prayer] on that basis, then prostrate twice." Agreed upon. And in a narration of al-Bukhari: "Let him complete [it], then give salam, then prostrate." And Muslim has: The Prophet ﷺ performed the two prostrations of forgetfulness after the salam and the talking.