M.
You've received some great responses already, and I absolutely agree that this sounds like he is NOT intending to purposefully poop his pants. Steer away from shaming, punishment, and additional stress -- focus on the physiological things that could be going on. Undiagnosed food allergy will absolutely cause continence issues, from constipation to diarrhea to not being able to notice the sensations of impending pee/poop. Is there a particular food that your son is enamored of to the point of almost seeming addicted (common culprits are cow's milk products, soy, wheat, eggs - though it could be any food that he persistently asks for and eats in quantity)? The next step would be to eliminate the suspected food completely from his diet and see if his continence/ability to control his bowels returns while on a "clean" diet. While you can ask your doc about this, you really don't have to -- you won't harm your son by temporarily restricting his diet for 1-3 weeks to see if it has a positive impact on his ability to control his bowels.
This is a sensitive issue, to be sure - I feel for your son, as well as for you, the mom! Hang in there, provide him with lots of empathy, love, and support, and be on the same team, as all of this will get you through it faster. Best of luck! Hope you're able to pinpoint the cause of the problem quickly.