The Messenger of Allah ﷺ partitioned off a small enclosure using a palm-leaf mat or a reed mat, and he came out to pray within it. Some men followed him there and joined him in his prayer.Then they came one night and waited, but the Messenger of Allah ﷺ was slow in coming out to them. He did not come out, so they raised their voices and threw pebbles at the door. The Messenger of Allah ﷺ came out to them angry and said to them, "Your persistence has gone on until I feared that this prayer would be made obligatory upon you. So pray in your homes, for the best prayer a person offers is in his home, except for the obligatory prayers."
احتجر رسول الله ﷺ حجيرة بخصفة أو حصير، فخرج رسول الله ﷺ يصلي فيها. قال: فتتبع إليه رجال، وجاوا يصلون بصلاته، قال: ثم جاؤا ليلة فحضروا. وأبطا رسول الله ﷺ عنهم، قال: فلم يخرج إليهم، فرفعوا أصواتهم، وحصبوا الباب، فخرج إليهم رسول الله ﷺ مغضبا فقال لهم رسول الله ﷺ: مازال بكم صنيعكم حتى ظننت أنه سيكتب عليكم. فعليكم بالصلاة في بيوتكم، فإن خير صلاة المرء في بيته إلا الصلاة المكتوبة.
Bukhari narrated it in the Book of adhan (731), and Muslim in the Book of the Prayer of Travelers (781), both through the route of Salim Abu Nadr, freedman of Umar bin Abdullah, from Busr bin Saeed, from Zayd bin Thabit, and he related it, the wording being Muslim's.In Bukhari's wording, "That was during Ramadan, so he prayed in it for several nights, and some of his companions prayed following his prayer. When he learned of that, he began sitting down, then he went out to them and said," and he related the rest similarly.