It is mustahabb to close the doors of houses at night
It is narrated in a saheeh report that the Prophet (peace and blessings of Allaah be upon him) commanded us to close the doors and mention the name of Allaah at night, when night begins, when going to sleep. That is so that the Muslim may protect his house and his family from any harmful devil coming in, whether from among mankind or the jinn, and from harmful animals or insects coming in.
It was narrated from Jaabir ibn ‘Abd-Allaah (may Allaah be pleased with him) that the Prophet (peace and blessings of Allaah be upon him) said:
“When the wings of the night spread – or when evening comes – keep your children in, for the devils come out at that time. Then when part of the night has passed, let them go. And close the doors and mention the name of Allaah, for the shaytaan does not open a closed door. And tie up your waterskins and mention the name of Allaah, and cover your vessels and mention the name of Allaah, even if you only put something over them, and extinguish your lamps.”
Narrated by al-Bukhaari (3280) and Muslim (2012). A version narrated by Muslim says:
“Cover vessels, tie up waterskins, close doors and extinguish lamps, for the shaytaan does not undo waterskins or open doors or uncover vessels.”
Imam al-Nawawi included this in a chapter entitled:
Chapter of the command to cover vessels, tie up waterskins, close doors and mention the name of Allaah over them, and extinguish lamps and fires when going to sleep, and keeping children and livestock in after sunset. End quote.
Muslim (2013) narrated in the same chapter that Jaabir ibn ‘Abd-Allaah (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “Do not let your animals and children go out when the sun has set, until the first part of the night is over, for the devils come out when the sun sets, until the first part of the night is over.”
Ibn Hibbaan narrated it in his Saheeh (4/90) as follows:
“Tie up your water skins and close your doors when you go to bed at night, and cover food and drink, for the shaytaan comes, and if he does not find the door closed he will enter, and if he does not find the waterskin tied up he will drink from it, and if he finds the door closed and the waterskin tied up, he does not open any water skin and he does not open a closed door, and if one of you cannot find something to cover his vessel in which is his drink, let him a place a stick over it.”
Imam Ibn Abd al-Barr (may Allah have mercy on him) said:
In this hadeeth there is a command to close doors of houses at night. This is a Sunnah which is enjoined to protect people against the devils of mankind and the jinn. As for the words “the shaytaan does not open a closed door and he does not untie a water skin” this is telling us of the blessing of Allaah, may He be glorified and exalted, to his human slaves, for he(the shaytaan) has not been given the power to open the door, or undo a water skin or uncover a vessel; these things have been forbidden to him, even though he has been given the power to do some things that are more difficult than that, such as going through and penetrating in ways that man cannot. End quote.
Al-Istidhkaar, 8/363
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
Ibn Daqeeq al-‘Eid said: in the command to close doors there are both religious and worldly benefits which protect lives and wealth from evildoers, and especially the devils.
As for the words “the shaytaan does not open a closed door,” this is an indication that the command to close doors serves the purpose of keeping the shaytaan away from mixing with people. The reason given is something that can be known through Revelation. The definite article is referring to the type, it does not mean any specific individual. End quote.
Fath al-Baari, 11/87.
He also said (may Allah have mercy on him):
Al-Qurtubi said: All commands on this issue are aimed at serving an interest for man, and are to be understood as recommendations, especially with regard to the one who does that with the intention of following the command.
Ibn al-‘Arabi said: Some people think that the command to close doors is general and is applicable to all times, but that is not the case. Rather it is limited to the night. It is as if the night is singled out in this case because the day is usually the time when people are awake, unlike the night. The whole idea is connected to the shaytaan, because he is the one who makes the mouse burn the house. End quote.
Fath al-Baari, 6/356 -- 357
Al-Khateeb al-Sharbeeni al-Shaafa’i (may Allaah have mercy on him) said:
When night comes, it is Sunnah to cover vessels even if only with a stick, to tie up water skins, and to close doors, mentioning the name of Allaah in all three cases, and to keep children and livestock in during the first part of the night, and to extinguish lamps when going to sleep. End quote.
Mughni al-Muhtaaj, 1/31
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
When going to sleep, one should close the door. End quote.
Sharh Riyaadh al-Saaliheen,.
See also the answer to question no. 125922.
And Allaah knows best.