The Prophet ﷺ set up a small enclosure in the mosque made of reed mats and prayed inside it for several nights. People gathered around him, but then they no longer heard his voice and assumed he had fallen asleep. Some of them began clearing their throats hoping he would come out to them.He said, "You kept up what I saw of your behavior until I feared that this prayer might be made obligatory upon you. Had it been made obligatory, you would not have been able to keep it up. So pray in your homes, people, for the best prayer a person offers is in his home, except for the prescribed prayers."
قال حدثنا عفان حدثنا وهيب حدثنا موسى بن عقبة قال سمعت أبا النضر يحدث عن بسر بن سعيد
أن النبي ﷺ اتخذ حجرة في المسجد من حصير فصلى فيها رسول الله ﷺ ليالي حتى اجتمع إليه ناس ثم فقدوا صوته فظنوا أنه قد نام فجعل بعضهم يتنحنح ليخرج إليهم فقال ما زال بكم الذي رأيت من صنيعكم حتى خشيت أن يكتب عليكم ولو كتب عليكم ما قمتم به فصلوا أيها الناس في بيوتكم فإن أفضل صلاة المرء في بيته إلا الصلاة المكتوبة
Its isnad is sahih. Its narrators are trustworthy and reliable imams. Wahib is Ibn Khalid bin Ajlan. Musa bin Uqba is the son of Abu Ayyash, the jurist. Busr bin Saeed is the Madinan, the Ansari, their freedman. Abu Nadr is Salim bin Abu Umaya, the Madinan jurist.Bukhari related the hadith, 9/117, in the Book of Holding Fast, chapter on what is disliked of excessive questioning, and Muslim, 1/540, number 781, and Abu Dawud, 2/69, number 1447, and Nasai, 3/198, number 1599, and Ibn Majah, 1/303, number 942.