Question: If a man goes to the mosque before Ẓuhr, for example, and lies down there until the time of the adhān—intentionally—because if he lay down at home he might miss Ẓuhr: is that permissible?
Answer: If that is the case, then it is permissible—indeed, it is preferable—because it helps to maintain the congregational prayer. It has come that “Waiting for prayer is [counted as] prayer,” and the Exalted
says: “Maintain with care the [obligatory] prayers and the middle prayer …” [Al-Baqarah:238].
Source : Min Thimār al-ʿIlm wa al-Ḥikmah vol.1