Disclaimer: I don't believe in the use of any form of punishment in parenting, and I further believe that if a consequence is being arbitrarily decided by a parent, then that's just a punishment with the added insult that the parent won't even own up to the fact that it is, so I'll have none of those either.
You've already identified that you have two, possibly conflicting, objectives here: to teach your child what not to do, and to reinforce that telling you was the right thing to do. The first thing you need to do is find out which of those objectives have priority, if they are indeed in conflict. To me that's dead simple, I will always value what strengthens the parent-child relationship. Having a relationship where my child will feel safe to tell me about anything is one of my absolute top priorities in parenting.
Furthermore, I believe the apparent conflict of these objectives is superficial, as establishing a relationship of love and trust will put you in a better position to guide their actions, where your opinion will matter more, and your role in modelling desired behaviour will be more effective.
With any such confession, it will probably be helpful to first distinguish whether the child is coming to you with a true confession, or just sharing something with you without realizing you'll think there was anything wrong with it.
In the former scenario, my first response would always be to reinforce that you're glad they're telling you. It seems they have already realized that they've done something wrong, so you don't need to stress that. There's a fine line between teaching the child they've done bad, and causing them to feel that they are bad, that you never want to cross, so if you have reason to believe the first part is taken care of, you don't need to go there at all. Instead, you can guide them to contemplate their behaviour by asking some leading questions. "Thank you for letting me know. And how did that make you feel?" and moving on from there.
With the very young, it's conceivable that they're coming to you with something they suspect was bad, in order to gauge your reaction, in which case there'd be a point in more explicitly pointing out why the behaviour was problematic. In these scenarios, and in the cases where you think the "confession" is entirely accidental, I'd make an effort to point out the desired behaviour, and the positive consequences from that, rather than telling the child not to do what they did, and the negative consequences of that. We often give our children directions in the form of "Don't do X". For us adults, who already know the desired behaviour, that seems about equally straightforward as "Do Y". If the child truly doesn't know what's right and wrong in a given situation, though, such directions are terribly unhelpful and difficult to parse. Imagine driving to a place you've never been only by following GPS directions, and the speech synthesis kept talking to you in the form of "In the crossing ahead, don't turn right." or "Oh, you should've taken a turn earlier." Best case, it's just a really mentally draining way of guiding you, and in the worst case it's actually insufficient information to getting you where you need to be.
If you think the child has no idea they've just confessed to something bad, but is actually sharing something they were excited about, you may also want to mind the anticlimax of running head first into an unexpected lesson. Take care of their excitement first, and take the time to see the child. "You think poo is funny, hey? I get it, I think it's funny to. But also ew, yucky. Poo should be in the toilet, and nowhere else."