I'm sorry, I hope he pulls through.

While I doubt this helps explain anything, I saw my rescue Sinaloan do something similar. A pet store employee had purposely stepped on him after he escaped. They figured a dead snake was better than a loose one. A friend brought him to me (still alive), I tried nursing him back to health, but he sadly only lived a few days.

I walked in the room finding him thrashing all over the place, rolling on his back and breathing quite heavily. He'd also twist around himself and squeeze, and lay on his back with his mouth open and twisted. It took him a little over 20 minutes. He went lethargic and passed.

I think they are just going through the final motions. I'm not sure it really explains the cause of the illness. Sometimes, they just aren't meant to make it.

If you are confident in all of you husbandry, positive he didn't ingest anything he shouldn't have, etc. You might want to take him to a veterinarian in the morning, either for a checkup or a necropsy. They could explain cause of illness/death.

I'm sorry if I was graphic..and I hope he does pull through.