I heard the Messenger of Allah ﷺ say, "Whoever is in the mosque waiting for the prayer is considered to be in prayer."
سمعت رسول الله ﷺ يقول: من كان في المسجد ينتظر الصلاة فهو في الصلاة.
Nasai (734) narrated it from Qutayba, who said, Bakr bin Mudar narrated to us from Ayyash bin Uqba, that Yahya bin Maymun narrated to him, saying, I heard Sahl Saadi say, then he mentioned the hadith. Its chain is hasan because of Ayyash bin Uqba, for he is truthful. Ibn Hibban graded it sahih (1752), narrating it via Zayd bin Hubab, from Ayyash bin Uqba with the same chain, and its wording is, "Whoever waits for the prayer is in a state of prayer as long as he does not break it."Imam Ahmad narrated it (22812) from Abu Abdul-Rahman Muqri and Abu Hasan Zayd bin Hubab, both of whom said, Ayyash bin Uqba narrated to us with the same chain, and its wording is, "Whoever sits in the masjid waiting for the prayer is in a state of prayer."