We have previously listed the reasons for which it is prescribed to do the prostration of forgetfulness in prayer, which are that a person has done something extra or omitted something, or he is confused about his prayer and does not know how many rak’ahs he has prayed. See question no. 12527
What is mentioned in the question about doing the prostration of forgetfulness because of one’s mind wandering is not one of the reasons for which the prostration of forgetfulness is prescribed. Shaykh al-Bahooti (may Allaah have mercy on him) said:
The prostration of forgetfulness is prescribed when one of the reasons for it is present, namely doing something extra, omitting something, or not being sure (of how many rak’ahs one has prayed), except in the case of janaazah (funeral) prayer. This does not include when one’s mind wanders, because it is not possible to avoid it, so it is forgiven.
Kashshaaf al-Qinaa’, 2/465.
The Standing Committee was asked: When I say the opening takbeer and start to recite al-Faatihah, I always lose my focus and my mind strays to matters other than prayer, until I finish the prayer…
Your prayer is valid if you have done all the obligatory parts of the prayer. Our advice to you is to ward off the Shaytaan from yourself as much as you can and strive your utmost, until these whispers depart from you and the plot of the Shaytaan is foiled.
Something that will help you to do that is turning to Allaah and seeking refuge in Him from the Shaytaan when beginning to recite, and to say that quietly to yourself all the time; pondering the meanings of the Qur’aan in such a way as to make you think of the greatness of Allaah; reciting takbeer (Allaahu akbar – Allaah is Most Great), tahleel (La ilaaha ill-Allaah – there is no god except Allaah), tasbeeh (Subhaan Allaah- glory be to Allaah) and tahmeed (Al-hamdu Lillaah – praise be to Allaah); remembering that you are standing before Allaah and conversing with Him in your prayer and that you must observe proper etiquette with Him; focusing on what you say when you speak to Him and call upon Him in du’aa’; hoping that Allaah will ward off these whispers and save you from the traps of the Shaytaan and that He will help you to turn to Him and turn away from the Shaytaan.
Fataawa al-Lajnah, 7/156. See also 7/36.
Shaykh Ibn Baaz (may Allaah have mercy on him) was asked about a woman whose mind wanders a great deal whilst praying – should she repeat her prayer?
Waswaas (whispers) come from the Shaytaan. What you have to do is to pay attention to your prayer, focus on it and be at ease with it, until you are doing it as it should be done. Allaah says (interpretation of the meaning):
“Successful indeed are the believers.
2. Those who offer their Salaah (prayers) with all solemnity and full submissiveness”
When the Prophet (peace and blessings of Allaah be upon him) saw a man who was not praying properly and was not at ease in prayer, he told him to repeat it and said to him: “When you stand to pray, do wudoo’ properly, then stand to face the qiblah and say takbeer. Then recite whatever you can of Qur’aan, then bow until you are at ease in bowing, then stand up until you are standing straight. Then prostrate until you are at ease in prostration, then sit up until you are at ease in sitting, then prostrate until you are at ease in prostration, then do that throughout your prayer.” Agreed upon.
If you remember that when you are praying you are standing before Allaah and conversing with Him, may He be glorified, that will prompt you to be focused and humble in your prayer. It will keep the Shaytaan away from you and protect you from his whispers.
If you experience a great deal of waswaas (whispers from the Shaytaan) in your prayers, then spit drily to your left three times and seek refuge with Allaah from the accursed Shaytaan three times, then he will depart from you in sha Allaah.
The Prophet (peace and blessings of Allaah be upon him) commanded one of his companions to do that, when he said to him: “O Messenger of Allaah, the Shaytaan makes me confused about my prayer.” See Saheeh Muslim, 2203.
You do not have to repeat your prayer because of waswaas, rather you have to do the prostration of forgetfulness if you did something that necessitates it, such as omitting the first tashahhud by mistake, or forgetting to say tasbeeh when bowing or prostrating.
If you are not sure whether you have prayed three rak’ahs or four, when praying Zuhr for example, then you should assume it is three and complete your prayer (by praying another rak’ah), and do the two prostrations of forgetfulness before saying the salaam.
If you are not sure whether you have prayed two or three rak’ahs in Maghrib, then you should assume it is two and complete your prayer (by praying another rak’ah), then do the two prostrations of forgetfulness before saying the salaam, because this is what the Prophet (peace and blessings of Allaah be upon him) enjoined. And Allaah is the Source of strength.
Fataawa al-Shaykh, 11/260
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) was asked: If a person is overwhelmed by wandering thoughts whilst praying, what is the ruling on his prayer? How can he rid himself of these thoughts?
He replied: In this case, if a person is overwhelmed by thoughts of either worldly matters or religious matters whilst praying, such as if he is a seeker of knowledge and when he starts to pray his mind wanders to thoughts of issues of knowledge, and this happens during most of his prayer, most scholars are of the view that his prayer is still valid and that it is not invalidated by this waswaas, but it is severely lacking. A person may be distracted whilst praying so only one-half of it, or one-quarter, or one-tenth or less, is recorded for him, as it says in Saheeh al-Musnad, 18400; Abu Dawood, 796.
But he has discharged his duty, even if that happened a great deal. But he should be focused when praying, because that is khushoo’ (proper focus and humility), and khushoo’ is the essence and spirit of prayer.
The remedy for that is to do what the Prophet (peace and blessings of Allaah be upon him) commanded, namely spitting drily to the left three times and seeking refuge with Allaah from the accursed Shaytaan. If he does that, Allaah will take it away.
If a person is praying in congregation, standing in the row, then he cannot spit because there are people to his left. In that case he should just seek refuge with Allaah from the accursed Shaytaan. If he does that and repeats it, Allaah will take that away from him. And Allaah is the Source of strength.
Fataawa al-Shaykh, 14/88.