It's not a fail. They get stuck together as it sometimes takes time for the semen to leave the male into the female so they stick like this so that this male has the best chance of getting the female pregnant instead of another male.
Because the transfer of seminal fluid in the dog takes some time, the base of the penis swells in order to prevent the tie from breaking too early, thus ensuring that the semen is completely ejaculated and the bitch has the best possible chance of getting pregnant by this male.
This is an evolutionary mechanism. As soon as the bitch "takes" (i.e. gets pregnant), she will go out of season -- otherwise, she will continue to stand for/breed with (potentially) other males until she's pregnant -- the tie helps ensure that particular male will be the one passing on his genetic material.