Everything is very simple - they do it in order to share their scent with other dogs. That is, in simple words, they can mark their territory in this way.