I once had a desert king snake that developed a huge tumor, the vet removed the tumor and sewed her up, but when she came out of the anesthetic she started biting the incision, just clamped right down on it and wouldn't let go. The vet thought that she was attacking the thing that was causing her pain.
I suspect that pain is also why some snakes wind up on their backs. Just like females will flip over when they're full of eggs in order to relieve the pressure, I think it's a good bet that snakes that are dying and probably in pain will flip over in order to relieve the pain.