All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
What people claim about the soul of a dead person roaming in his house for certain days after his death, etc., is not correct. As per the authentic Ahadeeth, when the Angel of death takes away the soul of a Muslim person, the other angel accompanying him immediately puts it in the shroud that suits it. And then they take it to the Heavens. They pass all the heavens one by one receiving a welcome till they reach the seventh Heaven. Then Allah Commands them to Register the Book of His Servant in Iliyyeen, (i.e. the seventh Heaven where the souls of Believers are). At that place, this new arriving soul meets other believers' souls who died before, and they inquire about those people who were with them in the world and about their condition. If they hear good about them, they Praise Allah; otherwise, they ask forgiveness of Allah for them. And then that soul would be put back into its body and then two angels come to him, make him sit up and ask him: Who is your Lord? Who is your Prophet? And what is your religion? Allah makes him firm (with the true answer), so he replies “My Lord is Allah, my religion is Islam, and my Prophet is Muhammad . After that, according to some accounts, Allah Says: “My Servant has spoken the truth, so spread a bed for him in Paradise, clothe him from Paradise and open a door for him from Paradise. So, some of its air and perfume will come to him and a space will be made for him as far as the eye can see. A good-looking man in a decent dress and good perfume will come to him. He [the dead person] asks him: ‘Who are you?’ He replies: ‘I am your good deed.’ The deceased then asks Allah: ‘O Allah, establish The Day of the Hour so that I will return back to my family and to my property. He will be told: Sleep as a bridegroom sleeps, and no one awakes him except the most loving person to him. And when he is raised on the Day of Resurrection, he will feel that he still likes to sleep more. And his place of Paradise after entering it will be presented to him twice in a day, in the morning and in the evening." There is no contradiction between his sleeping and seeing the place being presented to him, since these matters are related to the Unseen, so one should believe in them as reported in the Quran and Hadeeth. The Hereafter life is not like this life, so one cannot compare them. Allah Says (what means): {It is not for a believing man or a believing woman, when Allah and His Messenger have decided a matter, that they should [thereafter] have any choice about their affair. And whoever disobeys Allah and His Messenger has certainly strayed into clear error.} [Quran 33:36]
In fact, we know that a sleeping person in this world has dreams that please him and some that make him feel sorrow, and he also dreams as if he stayed for a long period or only for a short period, etc. This experience helps us to understand that matters of the Hereafter are reasonable and not to be doubted.
As for the claim that the soul of the deceased person roams in his house for 40 days, then this is wrong. In fact, there is no sound Hadeeth proving that the souls of deceased persons come back after death. What is narrated on this subject is condemned by the eminent Muslim scholars and ruled out. Actually, the narration about such matters is fabricated.
All the details mentioned above pertain to the soul of the believer. As for the soul of a Kafir (unbeliever) after his death, it is taken to the nearest heaven of this world but the doors will not be opened for it as Allah mentioned in the Quran: {… the gates of Heaven will not be opened for them, nor will they enter Paradise until a camel enters into the eye of a needle. And thus do We recompense the criminals.} [Quran 7:40]
Allah Says (what means): {No! Indeed, the record of the wicked is in sijjeen.} [Quran 83:7] Sijjeen is a place at the bottom of the seventh earth where all the souls of disbelievers are imprisoned, then the angels throw their souls to the earth from the heaven.
Allah also Says (what means): {And he who associates with Allah - it is as though he had fallen from the sky and was snatched by the birds or the wind carried him down into a remote place.} [Quran 22:31]
When the soul of the deceased comes back to his body, two angels come to examine him. They ask him “Who is your lord”? “Who is your Prophet”? “And what is your religion”? The disbeliever will not be able to give the correct answer; he will give the wrong answer. So, he will reply: “Alas, alas, I do not know.” Then Allah Says [as in the Qudsi Hadeeth “He has lied”, so spread a bed for him from Hell, clothe him from Hell, and open for him a door into Hell.” Then some of its heat and pestilential wind will come to him, and his grave will be compressed, so that his ribs will be crashed together. And his place in Hellfire will be presented to him twice every day in the morning and in the evening till Allah will establish the Day of the Hour.”
Some scholars are of the view that just before the Day of Judgement, disbelievers will find a taste of nap and then they will resurrect so they become astonished and say as in the verse in which Allah Says (what means): {They will say, “O woe to us! Who has raised us up from our sleeping place?” [The reply will be], “This is what the Most Merciful had promised, and the messengers told the truth.”} [Quran 36:52]
For more benefit on the conditions of the soul after death and life after death, please refer to Fataawa 83540, 87936, 89454, and 82911.
Allah knows best.