Then he said: "Indeed, this prayer is not fit for anything of the speech of people; it is only glorification, magnification, and recitation of the Quran," or as the Messenger of Allah (peace be upon him) said. [Reported by Muslim]. He did not command him to repeat [the prayer], which indicates its validity. This is the school of al-Shafi'i. It is more appropriate that this be categorized under the two narrations regarding the speech of one who forgets, because he is excused just as [the other] is.
The second category is that one speaks out of forgetfulness. This is of two types: First, that one forgets that he is in prayer. Regarding this, there are two narrations. One of them is that the prayer is not invalidated. This is the view of Malik and al-Shafi'i, because the Prophet (peace be upon him) spoke in the hadith of Dhu al-Yadayn, and he did not command Mu'awiyah ibn al-Hakam to repeat [his prayer] when he spoke out of ignorance; and whatever one is excused for due to ignorance, one is also excused for due to forgetfulness. The second is that his prayer is invalidated, which is the view of al-Nakha'i, Qatadah, Hammad ibn Abi Sulayman, and the scholars of opinion (Ashab al-Ra'y), due to the generality of the hadiths prohibiting speech, and because it is not of the nature of what is prescribed in the prayer, so one is not excused for it due to forgetfulness, just like excessive movement not of the nature of the prayer.
The second type is that one thinks that his prayer has been completed, so he speaks. If this is a salutation (taslim), the prayer is not invalidated, according to a single narration, because the Prophet (peace be upon him) and his companions did it and built upon their prayer, and because its nature is prescribed in the prayer, so it is like adding something to it from its own nature. If it is not a salutation, then the transmitted view from Ahmad, in a narration by a group of his companions, is that if he speaks about something that completes the prayer or something related to the affairs of the prayer, like the speech of the Prophet (peace be upon him) with Dhu al-Yadayn, his prayer does not become invalid. If he speaks about something outside the affairs of the prayer, such as his saying: "O boy, give me water to drink," then his prayer is invalid. He said, in a narration by Yusuf ibn Musa: Whoever speaks out of forgetfulness in his prayer while thinking that his prayer has been completed, if his speech is regarding that which completes the prayer, he builds upon his prayer, just as the Prophet (peace be upon him) spoke to Dhu al-Yadayn. And when
(9) Omitted from M. (10) Yusuf ibn Musa al-'Attar al-Harbi. He was a Jew who converted to Islam at the hands of Imam Ahmad when he was a youth; his Islam was sincere, he adhered to [the pursuit of] knowledge, and he narrated many things from Imam Ahmad. Tabaqat al-Hanabilah 1/420, 421. (11) In M: "he thinks (yazunnu)".