The soul has an apparent and hidden link to the body.
At the time of death, this link is detached completely resulting in pain. On the other hand, at the time of sleep, the link is only broken apparently. The hidden link is still intact resulting in no pain at all.
and Allah Ta’ala Knows Best
Mufti Ebrahim Desai