I believe dogs do it to scratch their backs, as they have difficulty reaching their backs.
I think it's also a nice stress reliever, since many dogs enjoy writhing after a bath.
Thor loves to do it generally, and he also seems to consider it a good strategy for guarding his toys. He's always trying to roll over them on his back. Given that most of his toys are about half his size, it is very ineffective.