He was asked:
About distracting thoughts during prayer: What degree of them invalidates the prayer? What degree is disliked? Are any such thoughts permissible during prayer? Can a person be punished for any of them? What constitutes sincerity in prayer? And what is meant by the Prophet’s saying—may Allah bless him and grant him peace—“Each of you has only that part of his prayer to which he was attentive”?
He replied:
Praise be to Allah. Distracting thoughts are of two kinds:
The first does not prevent the reflection one is commanded to give to the good words and righteous deeds within prayer. Rather, these are merely passing thoughts. They do not invalidate the prayer, but someone whose prayer is free of them is better than someone whose prayer is not. The former resembles those brought near to Allah, while the latter resembles those who follow a moderate course.
The second kind prevents understanding and attentiveness of heart, leaving a person heedless. This undoubtedly deprives him of reward, as Abū Dāwūd narrated in his Sunan from Ammār ibn Yāsir that the Prophet—may Allah bless him and grant him peace—said: “A man may finish his prayer with only half of it recorded for him, or a third of it;