Abu Hurairah reported,

The Messenger of Allah ﷺ said, "When one of you enters the mosque, he is considered to be in prayer as long as the prayer is what keeps him there. The angels send blessings upon one of you as long as he remains in the place where he prayed, saying, 'Allah, forgive him. Allah, have mercy on him. Allah, accept his repentance,' so long as he does not break his wudu in it and does not cause harm in it."

Ibn Majah 799

Sahih

حدثنا أبو بكر بن أبي شيبة حدثنا أبو معاوية عن الأعمش عن أبي صالح

عن أبي هريرة قال

قال رسول الله ﷺ إن أحدكم إذا دخل المسجد كان في صلاة ما كانت الصلاة تحبسه والملائكة يصلون على أحدكم ما دام في مجلسه الذي صلى فيه يقولون اللهم اغفر له اللهم ارحمه اللهم تب عليه ما لم يحدث فيه ما لم يؤذ فيه

ابن ماجه 799صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Mosques and congregations
Chapter
Staying in the mosques and waiting for the prayer
Numbering
Darussalam 799
Ibn Majah 799