What is the ruling on speech made out of forgetfulness while praying?
Chapter on the Two Prostrations of Forgetfulness
Al-Mughni
Book of Prayer
Primary text
If a person forgets they are in prayer and speaks, there are two differing opinions. The first view, held by Malik and Ash-Shafi'i, states the prayer is not invalidated, citing the Prophet's speech in the Hadith of Dhu al-Yadayn and that someone excused for ignorance is also excused for forgetfulness. The second view, held by An-Nakha'i, Qatadah, Hammad ibn Abi Sulayman, and the Ashab ar-Ra'y, states the prayer is invalidated due to the general prohibition against speech and because the speech is not a type of action legislated within the prayer, thus forgetfulness is not a valid excuse for it, similar to excessive non-prayer related actions.
Supporting text
If a person speaks, believing their prayer is complete, and the speech is a concluding salutation (salam), the prayer is not invalidated by a single ruling, as the Prophet and his Companions did this and built upon their prayer, and because such speech is legislated within prayer, resembling an addition of the same kind. If the speech is not a salutation, the transmitted text from Ahmad indicates that if the speech pertains to completing the prayer or matters of prayer (like the Prophet's speech to Dhu al-Yadayn), the prayer is not invalidated. However, if the speech concerns matters outside the prayer, such as saying, 'O boy, give me water,' the prayer is void. There is another narration from Ahmad where any speech made in forgetfulness believing the prayer is complete invalidates the prayer. Another view is that the prayer is not invalidated in this situation regardless of the content, as it is a form of forgetfulness analogous to the ignorant speaker, supported by the Prophet's speech and his Companions building upon their prayer. A fourth view is that if the speaker is the Imam and speaks for the prayer's benefit, the prayer is valid, but if another speaks, the prayer is void.