Assalamualaikum ustaz. Can you explain when is it a person needs to perform the sahwi prostration? And if a person repeatedly forgets in prayer, does it mean that he has to perform the sahwi prostration repeatedly too?
Waalaikumussalam wrt. wbt.,
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
Lexically, the meaning of sahwi is forgetting or being distracted from something. Whilst what is meant by sahwi here is that an imperfection in prayer when a person is praying due to his forgetfulness or it is done intentionally. Hence, this prostration – which is performed at the end of prayer – is the ending to the imperfection.
It is performed by prostrating twice just as other prostrations with the intention of sahwi prostration. It is at the end of prayer before salam. The ruling of sahwi prostration is sunnah when one of the reasons for it to be performed occurs. 
The sahwi prostration is based on a source of a famous story of Zul Yadain, which is narrated by Abu Hurairah RA, he said:
صَلَّى بِنَا النَّبِيُّ صلى الله عَلَيْهِ وَسَلَّم الظُّهْرَ أَو الْعَصْرَ ، فَسَلَّم ، فَقَالَ لَهُ ذُو الْيَدَينِ : الصَّلَاةُ يَا رَسُولَ اللَّهِ ، أَنقصت ؟ فَقَال النبيُّ صلى الله عليه وسلم : أَحَقٌّ مَا يَقُول ؟ قالوا نعمْ ، فصلَّى ركْعَتَينِ أُخْرَيَتين ، ثمَّ سَجَدَ سَجْدَتَين
“The Prophet (ﷺ) led us in the `Asr or the Zuhr prayer and finished it with Taslim. Dhul-Yadain said to him, “O Allah’s Messenger (ﷺ)! Has the prayer been reduced?” The Prophet (ﷺ) asked his companions in the affirmative. So, Allah’s Messenger (ﷺ) offered two more rak`at and then performed two prostrations (of Sahu).” 
Imam al-Nawawi stated: Sahwi prostration is two prostrations where there is one sitting and it is sunnah for one to sit in iftirasy (the same way one sits during the first tahiyyat). Whilst, sitting in tawarruk (sitting in the position of the final tahiyyat) after both the prostrations until it ends with salam. The characteristics of the two prostrations are in its act of prostration and the dhikr recitation when the prostration is (the same with) the characteristics of all the prostrations in prayer. 
Regarding the recitation in sahwi prostration, some scholars explained that it is sunnah to recite:
سُبْحَانَ مَنْ لَا يَنَامُ وَلَا يَسْهُو
“Glory is to Allah who never sleeps or negligent.” 
However, it is prioritized to recite the same dhikr in prayer as stated by Imam Nawawi in the book Raudah al-Talibin (1/315)
Syeikh Dr Wahbah al-Zuhaili cited the opinion of scholars of madhhab Syafi’e regarding the attributed and recitation of dhikr in sahwi prostration, he said: “(the characteristics of sahwi prostration) the two prostrations in prayer in terms of its obligation and sunnah is to place one’s forehead, toma’ninah (pause and calmness), slight pressure, lifting one’s back, sit in iftirasy (the position of the first tahiyyat) in between the two prostrations and sit in tawarruk after that. One should set his intention in his heart, if he verbalizes his intention then his prayer is invalidated. There are some who are of the opinion that it is sunnah to recite: ‘سبحان من لا ينام ولا يسهو’ (Glory is to Allah who never sleeps or negligent) during the prostration. While others stated that: The dhikr in sahwi prostration is the same dhikr (tasbih) in the usual prostration in prayer.” 
Reasons that Lead to Sahwi Prostration
Answering the above question, among the reasons that necessitate a person to perform the sahwi prostration are:
- Leaving one of the ab’adh sunnah such as the first tasyahhud and qunut.
- Doubt or uncertainty of the number of rakaat of the prayer.
- Mistakenly commit an act that is restricted in prayer, of which if it is done intentionally, it would invalidate prayer.
- Made a mistake whether in the requisites or ab’adh sunnah or form of prayer not at its proper place. 
Hence, if one of the above reasons occur, a person should perform the sahwi prostration. It should be performed at the end of the prayer before salam. Whereas, if one gives salam before the prostration (sahwi) whether it is done intentionally or because he forgot, then the prostration (sahwi) expires. Consequently, if one forgets just for a short moment, then he can immediately perform the prostration with the intention of sahwi and give the salam again.
The Issue of One Repeatedly Forgets in Prayer
Regarding the second question, should we perform the sahwi prostration repeatedly if we repeatedly forget in prayer?
The answer is this isn’t necessary. Imam al-Rafi’e said: “If one repeatedly forgets in prayer, it is enough to perform the sahwi prostration (twice) at the end of the prayer.” 
Moreover, if a person left more than one of the stated reasons, then he only has to perform the prostration twice. This is explained by al-Khatib al-Syarbini who said:
“Sahwi prostration is twice regardless of the number of mistakes of forgetfulness, for Rasullullah PBUH only perform the prostration twice in the story of Dzulyadain, although there are numerous reasons (for the sahwi prostration). This happened when Rasullullah PBUH performed only two rakaat (in a prayer that is supposed to be four rakaat), then Rasullullah PBUH also talked and walked. The reason is all of these reasons are reconciled by the two sahwi prostration, whether they happen before, during or after the sahwi prostration.”
Although, if a person performed the sahwi prostration, then he forgets and talked or do other acts before salam or he performed the sahwi prostration trice, then it is not necessary for him to perform a second sahwi prostration. The reason is, it is uncertain that he’ll not forget for the next sahwi prostration and it will be never-ending.