Zayd bin Thabit reported,

The Prophet ﷺ set up a small enclosure of reed matting inside the mosque, and the Messenger of Allah ﷺ prayed within it for several nights until people gathered around him. One night they missed the sound of his voice and assumed he had gone to sleep, so some of them began clearing their throats hoping he would come out to them.He said, "What you have been doing has continued until I feared it might be made obligatory upon you, and 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."

Bukhari 7290

Sahih

حدثنا إسحاق أخبرنا عفان حدثنا وهيب حدثنا موسى بن عقبة سمعت أبا النضر يحدث عن بسر بن سعيد

عن زيد بن ثابت

أن النبي ﷺ اتخذ حجرة في المسجد من حصير فصلى رسول الله ﷺ فيها ليالي حتى اجتمع إليه ناس ثم فقدوا صوته ليلة فظنوا أنه قد نام فجعل بعضهم يتنحنح ليخرج إليهم فقال ما زال بكم الذي رأيت من صنيعكم حتى خشيت أن يكتب عليكم ولو كتب عليكم ما قمتم به فصلوا أيها الناس في بيوتكم فإن أفضل صلاة المرء في بيته إلا الصلاة المكتوبة

البخاري 7290صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Adhering to the Book and the Sunnah
Chapter
What is disliked of excessive questioning and burdening oneself with what does not concern him
Numbering
Darussalam 7290
Bukhari 7290