Ego is the physical and character part, of any being. When death is about to occur, the character part of Ego serves as a messenger between the physical body and the spiritual. It informs the spiritual of its intentions to experience physical death.
When that occurs, the spiritual realizes that it can leave before the experience begins. It can then detach by having final goodbyes, messages, or confessions. This allows the spiritual to free itself of certain anchors before leaving. It can then focus on deciding its next move such as reincarnation.
Once the spiritual leaves, the body stops responding. At the point of physical death, Ego has the ability to dissolve its energy and attach to any energy it attracts, including a different living physical body.