my guess its to get comfortable. kind of like that way humans toss and turn and get in all sorts of positions before finding a comfort zone. some also have a ritual. like me, I got in to bed on my back, turn to the side, move my legs, and sooth myself to sleep by moving my feet up and down and rubbing it on the sheets. it always soothes me. I find that my sister does the same. my husband finds it odd because he doesnt do It
Dogs are pack animals that in the wild cover a large area, typically in tall grass or pampas. The dogs sleep in a different place every night, so must walk down the tall grass to have a comfortable place to sleep. You will see the same behavior in other animals that travel over a wide area in the wild.