The other causes are not bad and I will list them here. Kids do not like using the toilet at school and hold it in all day till they get home. This causes cramps. Give them a mild laxative once a day for three days and see if the symptoms go away. See other articles on encopresis.
Kids are under stress now days and understandable if they listen to the news.
Just the normal stress of do your work and watch out for the bullies. This causes acid or a full blown ulcer. Or you can give them one tablet of over the counter Tagamet. These are not habit forming and can be given safely for a period of time. Food Allergy .