This question already has an answer here:
We got a kitten a while ago. She was about 8 weeks. We had her litter box downstairs but eventually moved it upstairs because she figured out how to go upstairs and was spending all her time up there. Fast forward a few weeks and she was doing great. She became less fearful in our house and loves attention and playing. All of a sudden she started pooping in our dining room. It is not daily but pushing weekly. When I catch her, after it happens (once we smell it), I put her over by it to look/smell it, then take her to her litter box in the bathroom and shut the door. What more can I do to stop this from happening?