I get this all the time. It is called dissociation. It happens when something is threatening you or scaring you or too hard to deal with. I have had this since childhood. I would dissociate while the sexual abuse was going on. I would feel outside of my body or floating above it. It was like I was watching a movie. No emotion, no pain. My mind was taken away from the situation, only the body was left.
This is a very common defense mechanism for people who have suffered great trauma. I am seeing a therapist and it is helping me a lot. I am working on not dissociating anymore and realizing that I don't need to do this because I am safe now. However it does come in really handy when I go to the dentist and it hurts!
If you are seeing a therapist you should tell them about the dissociation. If you are not seeing a therapist you might want to consider it. It is both educating me and helping me a lot.
take good care of yourselves