It's mostly a way to express dominance, you'll also see it in cats, dogs, birds, and lots of other animals that flex or arch their backs in the sudden presence of the opposite sex.
Sometimes they also do it as a self-defense mechanism against bigger and stronger creatures. If you're perceived as being strong, they won't attack.