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:
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”
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”
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
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
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.
End quote from Fath al-Baari by Ibn Rajab, 3/325
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.
End quote from Fath al-Baari, by Ibn Rajab, 3/326
For other scholarly opinions on this issue, please see al-Jaami‘ li Ahkaam al-Qur’an, by al-Qurtubi, 15/261; Fath al-Baari by Ibn Hajar, 11/114
However what appears to us to be the case is that what you mentioned in your question does not have anything to do with this issue at all; the departure of the soul during sleep only happens when one is actually sleeping, and it does not happen before sleeping as you mention.
Perhaps what is happening to you is a psychological matter or excessive preoccupation with death and the like.
We ask Allah to keep you safe and sound and to put your affairs straight.
And Allah knows best.