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 is His slave and Messenger.
The claim that a dead person’s soul roams in his house for 40 days after his death is unfounded. Saheeh (authentic) Hadeeths clarify that the souls of the dead that have been taken by the angel of death, whether believers or disbelievers, are not even left by the assisting angels for the blinking of an eye.
As for the soul of the believer, they place it in a worthy shroud and ascend with it to the heavens. They ask permission for the heavens to be opened and are granted it until they reach the seventh heaven. There, Allaah The Almighty orders the angels to register the person’s record in a high place in Paradise in the seventh heaven where the souls of the believers rest. The person’s soul meets the souls of the dead, who ask what it did. If it mentions something good, they praise Allaah and rejoice. If it mentions something evil, they ask Allaah to forgive it. They even ask whether the person was married. Then, the soul is returned to the body in the grave and two angels come and ask, "Who is your Lord, who is your Prophet, and what is your religion?" Allaah keeps it firm and it replies, "My Lord is Allaah, my Prophet is Muhammad , and my religion is Islam." Allaah The Almighty then Says: “My servant has spoken the truth, so spread a bed for him from Paradise, and open a door for him to Paradise,” so some of its air and scent reaches the person and a space is made for him as far as the eye can see in his grave.
Then, an elegantly-clothed and well-scented man comes to him and the person asks him who he is. The man replies, “I am your good deeds.” Upon hearing this he says, "O my Lord, make the Hour come so that I may return to my family and property.” He will be asked to sleep like the newlywed whom no person wakes up but his most beloved relatives. When he is resurrected, he feels he had slept for just a while. Meanwhile, he sees his seat in Paradise in the morning and the evening until the Hour comes.
It is important to note here there is no contradiction between being asleep and seeing a seat in Paradise in the morning and the evening because this matter is one of the Unseen which cannot be compared with this worldly life, and nor can a mind understand its essence.
Muslims must submit to the revealed laws of Allaah and believe in what was [authentically] narrated from the Prophet even if a person does not understand them. Allaah The Almighty Says (what means): {It is not for a believing man or a believing woman, when Allaah and His Messenger have decided a matter, that they should [thereafter] have any choice about their affair. And whoever disobeys Allaah and His Messenger has certainly strayed into clear error.} [Quran 33:36]
We know that in this world a person sees in their dreams things that makes him happy or sad and he feels that he spent a long or short time there and the like. What then will life after death in the grave be like?
As for the souls visiting one another in graves, the Hadeeth narrated on this matter is not authentically attributed to the Prophet and Ibn Al-Jawzi listed it among the fabricated Hadeeths. The Permanent Committee for Islamic Research and Fataawa issued a Fatwa stating that there was no authentic Hadeeth that we can depend upon in this regard.
On the other hand, angels ascend with the soul of the disbeliever to the lowest heaven and ask permission to pass but they are not given this. Allaah The Almighty Says (what means): {Indeed, those who deny Our verses and are arrogant toward them - 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]
Afterwards, Allaah orders the person’s record to be registered in a narrow place in the lowest earth, the seventh deepest earth where the souls of the disbelievers are kept. Then the soul is roughly cast down to the earth. Allaah The Almighty Says (what means): {Inclining [only] to Allaah, not associating [anything] with Him. And he who associates with Allaah - 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 is returned to his body, two angels come and ask, “Who is your Lord? Who is your Prophet? What is your religion?” Allaah does not keep the person firm, and he replies, “Huh, Huh, Huh! I do not know.” Then, Allaah Says: “My servant has told lies, so spread a bed for him in Hell, and open a door for him to Hell.” So some of its heat and poisonous wind comes to him, and his grave is compressed until Allaah brings him to life on the Day of Resurrection. [Ahmad, Abu Daawood, Ibn Khuzaymah, Al-Haakim and others on the authority of Al-Baraa' Ibn ‘Aazib]
Some of the righteous predecessors stated that the dead sleep for a short while before the Hour comes, and when the call is made for the inhabitants of the graves, they say (what means): {"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]
Allaah Knows best.