The Messenger of Allah ﷺ said, "When one of you is uncertain during his prayer and does not know how much he has prayed, whether three units or four, let him cast aside the doubt and proceed on what he is certain of, then perform two prostrations before giving the closing salutation. If he had in fact prayed five units, these prostrations will make his prayer an even number for him, and if he had prayed a complete four units, they will be a humiliation for Satan."
قال رسول الله ﷺ: إذا شك أحدكم في صلاته فلم يذر كم صلى؟ ثلاثا أم أربعا؟ فليطرح الشك، وليبن على ما استيقن، ثم يسجد سجدتين قبل أن يسلم. فإن كان صلى خمسا شفعن له صلاته، وإن كان صلى إتماما لأربع كانتا ترغيما للشيطان.
Muslim narrated it in the Book of Mosques (571) via Sulayman bin Bilal, from Zayd bin Aslam, from Ata bin Yasar, from Abu Saeed Khudri, mentioning the same. There is disagreement regarding Zayd bin Aslam. Sulayman bin Bilal narrated it from him as a connected chain, as you have seen, and likewise it was narrated by each of the following.Hisham bin Saad, whose chain Abu Awana traced (2/193), saying, Yunus bin Abdul-Ala informed us, saying, Ibn Wahb informed us, from Hisham bin Saad, from Zayd bin Aslam, with the same hadith as Sulayman bin Bilal in full.Abu Ghassan, who is Muhammad bin Mutarrif, from Zayd bin Aslam, whose chain was also traced by Abu Awana and Ahmad (3/87).Abdul-Aziz bin Abu Salama, from Zayd bin Aslam, whose chain was also traced by Abu Awana, Nasai (123), and Ahmad (3/84).Fulayh bin Sulayman, from Zayd bin Aslam, whose chain was traced by Ahmad (3/72), from Yunus bin Muhammad, who said, Fulayh bin Sulayman narrated to us, with this chain.Muhammad bin Ajlan, from Zayd bin Aslam, whose chain was traced by Abu Dawud (1024), Nasai (1238), and Ibn Majah (1210). Abu Dawud and Ibn Majah added, and the wording is Ibn Majah's, "If his prayer was complete, then the extra rakat becomes a voluntary one, and if it was incomplete, then the extra rakat completes his prayer, and the two prostrations humiliate the devil." In Abu Dawud's wording, "the two prostrations that humiliate the devil." Hakim graded it sahih (1/327) according to the criteria of Muslim, except that Muhammad bin Ajlan was narrated from by Muslim only as a corroborating narrator, and it is Hakim's habit not to distinguish between a primary narration and a corroborating one.Dawud bin Qays, from Zayd bin Aslam with this chain. Muslim narrated it in his Sahih from Ahmad bin Abdul-Rahman bin Wahb, who said, my uncle Abdullah (Ibn Wahb) narrated to me, Dawud bin Qays narrated to me, with this chain connected, as Sulayman bin Bilal said.However, Bayhaqi narrated (2/331) via Bahr bin Nasr, who said, it was read out to Ibn Wahb, Malik bin Anas, Dawud bin Qays, and Hisham bin Saad informed you that Zayd bin Aslam narrated to them, from Ata bin Yasar, that the Messenger of Allah ﷺ said, and he mentioned the hadith. Bayhaqi said, except that Hisham traced it up to Abu Saeed Khudri. This is how Bahr bin Nasr Khawlani and others narrated it from Ibn Wahb, while Ahmad bin Abdul-Rahman bin Wahb narrated it from his uncle Ibn Wahb, making the connected chain belong to Dawud bin Qays. He then narrated it via Abu Bakr bin Ishaq, who said, Ahmad bin Abdul-Rahman bin Wahb narrated to us, with this chain, and said, Muslim narrated it in the Sahih from Ahmad bin Abdul-Rahman bin Wahb, and Bahr bin Nasr's narration seems to be more sahih. A group of narrators connected the hadith from Zayd bin Aslam, along with Sulayman bin Bilal and Hisham bin Saad. End of quote.I say, Ibn Khuzayma did not mention this chain in his Sahih (1024). Rather, he narrated it through other connected chains from Abu Saeed Khudri, among them Yunus bin Abdul-Ala, who said, Ibn Wahb narrated to us, Hisham, that is, Ibn Saad, informed me, with this chain. Perhaps he included it in the larger Musnad.As for Malik, he related it with an incomplete chain from Zayd bin Aslam, from Ata bin Yasar, in the Book of Prayer (62). Ibn Abdul-Barr said, this is how all the narrators related it from Malik, except what was narrated from Walid bin Muslim, from Malik, from Zayd bin Aslam, from Ata bin Yasar, from Abu Saeed, from the Prophet ﷺ, in Al-Istidhkar (4/348).Abu Dawud said, after narrating it via Malik and Yaqub bin Abdul-Rahman Qari with an incomplete chain, likewise it was narrated by Ibn Wahb from Malik, and Hafs bin Maysara, and Dawud bin Qays, and Hisham bin Saad, except that Hisham traced it up to Abu Saeed Khudri.The meaning of this is that Malik was not alone in relating this hadith with an incomplete chain, rather he was also corroborated by Hafs bin Maysara, Dawud bin Qays, and Yaqub bin Abdul-Rahman Qari. It thus appears from this that Zayd bin Aslam used to narrate it in two ways, incomplete and connected. This goes back to whether he was attentive or not, for when he was attentive he connected it, and when he was not attentive he related it incompletely, as is known in the science of hadith. The stronger evidence lies with whoever has the additional element, which is the connection of the chain. By this, the hadith of Abu Saeed Khudri is established as sahih, and Muslim, may Allah have mercy on him, was correct in choosing the connected version.This concerns the imam who stood up for a fifth rakat, and someone alerted him by saying "subhanallah" but he did not turn his attention to it and thought he had not erred. Should those praying behind him stand up with him or not? Shaykh al-Islam answered, saying, "If they stood up with him out of ignorance, his prayer is not invalidated, but if they know better, they should not follow him, rather they should wait for him until he completes the prayer with them, or they should end their prayer before him, and waiting is better." Majmu Fatawa (3/53).I say, waiting is the sahih position according to the scholars, until they end the prayer together with the imam. As for one who stands up for a fifth rakat while knowing it is wrong, his prayer is invalid, and he must repeat the prayer.