Child development specialists believe that a situation like this is a classic power struggle. It may have started with some change in the family dynamics or a specific event that distressed or angered the regressing child (perhaps being teased or bullied by someone and wishing for the tender, loving attention they got in babyhood). A child has very little power, so behavior like this gets attention. Punishing for potty mistakes often simply makes the struggle worse.
(There's also a possibility that he has a physical problem that worries or shames him; more on that at the end.)
I'd have a quiet talk with the child if he were my son. I'd open with, "So, sweetie, you've been making a lot of pooping mistakes lately. Will you tell me what that's about?" Then give him lots of space to answer. He'll probably start with "I don't know!" and possibly refuse to meet your eyes, at which point you could say, "You were doing so well, and I thought you were happy being able to use the toilet." Then wait. Every little thing that he offers, respond to kindly with, "Hmmm," or "I see." If he gets to something with some emotional content, draw him out with short, simple, encouraging questions.
At the end of the talk, you may want to offer him a choice. Put a very small amount of power in his hands. Suggest, "Well, this is sure not a nice thing for either you or me, so, would you like to be in diapers again? Then you can decide for yourself when you're ready to be a big boy." Kids often respond well to this, and will want to get the big boy pants back after they're sure you won't try to force them to abandon the diapers. This may take a few days or a few months, often less if their peers are using the toilet. But kids usually will make this choice for themselves when they are ready. And diapers do make for an easier cleanup than undies.
But if your little guy tends to have constipation, there is also the possibility that he's developed a condition called encopresis, in which solid poop blocks the bowel, causing stretching and numbing, and he actually can't feel it when fresh, wet poop gets forced past the blockage and he soils his pants. Then he might also avoid telling you because he's embarrassed. If he appears to be leaking fairly liquid poop, get him quickly to a pediatrician – this situation can become very hard to clear out and generally requires medical oversight.
Good luck. I hope you get to the bottom of the problem soon.