Do the Devils Enter the Mosques?
There are proven reports in the sunnah (prophetic teachings) which indicate that the devils do enter the mosques, because they go into the gaps in the rows and whisper (waswas) to the individual when he is praying so as to distract him and rob him of proper focus (khushoo‘).
Abu Dawood and Ahmad narrated, in a report that was classed as saheeh (authentic) by al-Albani in al-Mishkat, from Anas ibn Malik (may Allah be pleased with him) that the Messenger of Allah (peace and blessings of Allah be upon him) said: “Consolidate your rows, make them close together and stand with your necks in line with one another, for by the One in Whose hand is my soul, I see the devils going into the gaps in the rows as if they are little lambs.”
Muslim narrated in his Saheeh from Abu’l-‘Ala that ‘Uthman ibn Abi’l-‘As came to the Prophet (peace and blessings of Allah be upon him) and said: O Messenger of Allah, the shaytan (devil) interferes between me and my prayer and my recitation, and he makes me confused. The Messenger of Allah (peace and blessings of Allah be upon him) said: “That is a devil called Khinzab. If you feel that, then seek refuge with Allah from him and spit dryly to your left three times.” He said: I did that and Allah took him away from me.
Muslim also narrated that Abu’d-Darda (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings of Allah be upon him) stood up (to pray) and we heard him saying: “I seek refuge with Allah from you.” Then he said: “I curse you with the curse of Allah” three times, and he stretched out his hand as if to take something. When he had finished praying, we said: O Messenger of Allah, we heard you say something during the prayer that we have not heard you say before, and we saw you stretch out your hand. He said: “The enemy of Allah, Iblis, came with a brand of fire to throw it in my face…”
Al-Bukhari, Muslim and others narrated from Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings of Allah be upon him) said: “When the call to prayer is given, the shaytan runs away breaking wind loudly so that he will not hear the call. Then when the call has ended, he comes but when iqamah (final call before prayer) for prayer is given he runs away, then when the iqamah has ended, he comes back so that he can whisper to the individual, saying: Remember such and such, remember such and such -- about things that he was not thinking about, until he confuses the man and he does not know how many (rak‘ahs/units) he prayed.
These hadeeths (narrations) and others clearly indicate that the devils do enter the mosques, but when they hear the adhan they run away to somewhere where they cannot hear the call, then they come back after that and distract a person from his prayer and recitation.
And Allah knows best.