All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
Jaabir ibn ‘Abdullaah narrated that the Prophet, sallallaahu ‘alayhi wa sallam, said: "When night falls (or when it is evening), stop your children from going out, for the devils spread about at that time. When part of the night has passed, release them and close the doors and mention Allaah's Name, for the devil does not open a closed door. And tie the mouths of your water-skins and mention Allaah's Name; cover your containers and utensils and mention Allaah's Name. Cover them even by placing something across them, and put out your lamps." [Al-Bukhari and Muslim]
Ibn ‘Abdul-Barr said: "This is a prophetic tradition enjoined to keep people safe from the devils among mankind and jinn. The Prophet's words 'the devil does not open something closed, and does not untie a water skin,' consists in his informing about Allaah's favor to His human slaves in that the devil was not given the power to open doors, untie water skins or uncover utensils, and that the devil was deprived of this ability, even though he was given the ability to do what is worse than this, like entering places humans cannot enter." [End of quote – excerpted from the book entitled Al-Istithkaar]
Windows are apparently analogous to doors regarding the command to close them. The reason for this is to protect people and property against transgressors and to prevent the entry of the devils. This is what Ibn Daqeeq Al-‘Eed referred to when he said: "The command to close doors entails the religious and worldly benefits of guarding the lives and money of people from transgression and mischief, especially from the devils." [End of quote]
Nonetheless, the command here has the effect of recommendation and advice (not obligation) as some scholars have said. Ibn Hajar quoted Al-Qurtubi as saying: "All the commands mentioned on the matter are a matter of advice for the general good and it is possible that they are for religious desirability, especially in relation to one who does that with the intent of obeying the command." [End of quote]
Moreover, a Fatwa of the Standing Committee reads: "The authentic Hadeeth reported in Al-Bukhari, 'When night falls (or when it is evening), stop your children from going out' and which continues, 'and put out your lamps' – is this a command (an obligation)? If it is desirable, then what indicates that it has the effect of desirability instead of obligation?
Answer: These commands mentioned in the Hadeeth are understood as recommendations and advice according to the majority of the scholars, as a group of scholars have stated, among them Ibn Muflih in his book Al-Furoo‘ (1/132) and Ibn Hajar in his book Fat-h Al-Baari (11/87). And Allaah knows best." [End of quote]
Allaah Knows best.