There is clear evidence in the Qur’an and Sunnah which indicates that the soul is taken when one falls asleep, and that sleep is a kind of death. This evidence includes the following:
1. Allah, may He be glorified and exalted, says (interpretation of the meaning):
“It is Allah Who takes away the souls at the time of their death, and those that die not during their sleep. He keeps those (souls) for which He has ordained death and sends the rest for a term appointed. Verily, in this are signs for a people who think deeply”
2. And He, may He be glorified, says (interpretation of the meaning):
“It is He, Who takes your souls by night (when you are asleep), and has knowledge of all that you have done by day”
3. It was narrated from Abu Qataadah (may Allah be pleased with him) that when they slept and missed the prayer, the Prophet (blessings and peace of Allah be upon him) said: “Verily Allah took your souls when He willed, and He returned them when He willed.”
Narrated by al-Bukhaari, 7474
4. It was narrated that Abu Juhayfah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) was on a journey during which they slept until the sun rose. He said: “Verily you were dead and Allah returned your souls to you; whoever sleeps and misses a prayer, let him offer it when he wakes up, and whoever forgets a prayer, let him offer it when he remembers.”
Narrated by Abu Ya‘la in al-Musnad, 2/192; classed as saheeh by al-Albaani in Irwa’ al-Ghaleel, 1/293
5. It was narrated from Hudhayfah (may Allah be pleased with him) that when the Prophet (blessings and peace of Allah be upon him) woke up, he would say: “Al-hamdu Lillahi alladhi ahyaana ba‘da ma amaatanaa wa ilayhi an-nushoor (Praise be to Allah Who has given us life after He caused us to die, and to Him will be the resurrection).”
Narrated by al-Bukhaari, 6312. It was also narrated by Muslim in his Saheeh, 2711, from al-Bara’ (may Allah be pleased with him).
This evidence was quoted by al-Haafiz Ibn Rajab (may Allah have mercy on him), who then said:
The verse indicates that sleep is a death, and the hadeeth indicates when a person sleeps his soul is taken. They both indicate that the soul that is taken in death is the soul that is taken during sleep.
But the taking of the soul in sleep does not necessarily mean that it is completely separated from the body, as happens in death; rather the fact that the life remains in the body during sleep indicates that the soul is still connected to the body during sleep, but the connection is less than the connection when it is awake. Not every departure of the soul from the body implies death; rather what happens to the body differs according to the type of separation.
Ibn Rajab (may Allah have mercy on him) said:
The taking of the soul from the body does not necessarily mean that it has departed from the body altogether; rather it may be taken whilst some kind of connection is still present, as in the case of one who is sleeping.
And Allah knows best.
(source - islam Q and A)