Great question, although I am sorry your kiddo is having such difficulties. You asked for ideas, so here are a few thoughts I would have if you were a client of mine:
(1) sometimes, kids can get constipated very easily (diet plays a big role in this, physiology can as well). whatever the cause, if they have a lump of hard stool in their colon, it impedes progress for other solid stool to get around the mass. Then, liquid stool can squeeze out the sides and exit outside of the control of the kiddo. Laxatives and fiber will be necessary, although a more invasive procedure may be necessary to remove the initial mass. A check-up by the pediatrician will be necessary as the first step to rule out or treat any physical complications.
(2) Related to #1 above, if a kiddo is feeling tremendous anxiety - again, for whatever reason ambient in their life - then they may "bear down" and hold their stool in. Over time, the colon extracts all of the water from the mass and creates constipation. Too, even without constipation, sometimes anxious kids can hold their stool past the point that they can contain it, and it will leak or seep out. A check-up form the doc to rule out physical probs will be necessary, but if anxiety is the issue, a talk therapist who specializes in kids can help ease his fears/worries/traumas (whatever the case).
(3) At times kids can become defiant via their stool. They can act out aggression by smearing stool, expelling it in inappropriate places, or expelling it at inappropriate times. Talk therapy can help to resolve some of the familial issues that may be present and fueling the acting out.
(4) Finally, and this is again related to stress and anxiety, a kiddo can "regress" as a means of coping with the bad feelings they are having. If there is abuse or ambient stress in the household (or bullying at school?) sometimes kids will return to a more child-like (or infant-like, in the case of a 10-year-old kiddo) state as a means of avoiding the reality of their chronological age. Encopresis (the technical term for this phenomenon) can certainly be a part of that regression, as can enuresis (bed-wetting), temper tantruming, and other younger behaviors. Talk therapy again will be the best course of action.
I wish you well - it is not easy to see your kids upset, especially in a way that upsets us! If you are satisfied with the response, please hit "Accept." That is the only way I can receive credit for my answer. Thanks-