The answer is ... the soul or consciousness detaches from the physical body or its physical grid. There is nothing mystical about it. It is all science/physics. This can happen quickly or over time though both are the same as time is an illusion - or construct of physical reality that allows you to experience emotions.
What Happens in the Hours Before Death? Most People Don't Have a Clue. Live Science - May 9, 2019
According to a statement from the academy, death and dying have become such taboo subjects in Western cultures that many people resist talking about them. This reticence has resulted in a widespread cultural ignorance about death, the survey found. For example, only 42% of respondents said they turn to friends or family for information about death and end-of-life care, while just 22% said they'd be likely to ask medical professionals for information. Roughly the same percentage (20%) of people said they get their information on death from documentaries , and 16% said they get their information from fictionalized TV shows and films ...