The Prophet ﷺ set up a small enclosure made of reed mats inside the mosque, and the Messenger of Allah ﷺ prayed in it for several nights, until people gathered around him. One night they did not hear his voice and assumed he had fallen asleep, so some of them began clearing their throats hoping he would come out to them.He said, "Your behavior that I observed continued until I feared that this prayer would be made obligatory upon you, and had it been made obligatory, you would not have been able to keep up with it. So pray in your homes, people, for the best prayer a person performs is in his home, except for the obligatory prayers."
أخبرنا أحمد بن سليمان قال حدثنا عفان بن مسلم قال حدثنا وهيب قال سمعت موسى بن عقبة قال سمعت أبا النضر يحدث عن بسر بن سعيد
أن النبي ﷺ اتخذ حجرة في المسجد من حصير فصلى رسول الله ﷺ فيها ليالي حتى اجتمع إليه الناس ثم فقدوا صوته ليلة فظنوا أنه نائم فجعل بعضهم يتنحنح ليخرج إليهم فقال ما زال بكم الذي رأيت من صنعكم حتى خشيت أن يكتب عليكم ولو كتب عليكم ما قمتم به فصلوا أيها الناس في بيوتكم فإن أفضل صلاة المرء في بيته إلا الصلاة المكتوبة
Bukhari transmitted it in Sahih Bukhari, Book of Holding Fast to the Book and the Sunnah, Chapter on What is Disliked of Excessive Questioning, etc., no. 7290, from the hadith of Affan.Muslim transmitted it, Book of the Prayer of Travelers, Chapter on the Desirability of Praying the Voluntary Prayer at Home, etc., no. 781/214, from the hadith of Waheeb bin Khalid, with the same wording.It is also found in Al-Kubra, vol. 1291, 1292.