It's not exactly something they do on purpose . It's rare but they sometimes end up biting themselves thinking that they're body was the rat. The rat's scent most likely rubbed off on the snake, so while the snake was trying to find the head to start swallowing it latched on to itself.

Just my general thought of what probably happened. I've had my Kingsnake bite himself before accidentally thinking that his body was the rat I was trying to offer. This occasion happened more than once LOL.