What happens when he poops inside (what is your reaction)?

He might have learned that pooping on the rug gets him attention, even if it is negative attention.

A quick check up at the vet could rule out anything medically wrong.