An intestinal infection. The infection causes scarring on the lower intestinal lining which causes mucus to accumulate. This mucus is released with defecation.
Most often the cause is worms or some other parasite. You need to take your dog to the vet because it'll definitely take medicine to cure whatever the cause is.