He could have been a little bit constipated, and now when he moved his bowels tbat happened. Or he could have polyps, or a hemroid. Take him to the vet.
There are many reasons why. The dog can have a polyp or tumor in his large intestine. I know that if the dog eats something that it shouldn't that can cause it, happen to my dog, it was rotten fallen fruit from trees.