Abu Musa reported that a house was burnt down in Madinah during the night over its inhabitants. When their matter was reported to Allah's Messenger (ﷺ) , he said; This fire is an enemy of yours. So when you go to sleep, extinguish it.
Related hadith on this topic
Explanation & Benefits
Shaykh Abdul Sattar al-Hammad
Hadith Commentary:
(1)
In this hadith, the wisdom behind extinguishing the fire before sleeping is explained: there is a risk of burning from it. This applies to any fire, whether it is a lamp or a stove. In addition, the same ruling applies to gas heaters and electric bulbs.
(2)
Fire has been described as an enemy because there is always a risk of harm to life and property from it, just as there is danger from an enemy, even though it also has countless benefits.
(Fath al-Bari: 11/103)
Source: Hidayat al-Qari: Commentary on Sahih Bukhari, Urdu, Page: 6294