Why does a female dog lock on to a dog's penis?

The female does not "lock on" to the male's penis. The penis, once it has inseminated the female, enlarges and becomes stuck in the vagina. It's to keep other males from mating with that female for a period of time, while both dogs can still lookout for danger.