The most common reason for encopresis in a child of six is chronic constipation. However, the situation invites evaluation, first by the pediatrician, then by a pediatric gastroenterologist. Almost always, when a child this young is treated medically (don't take this on yourself) with a regimen (it might go on for a couple of months) of laxative and stool softener the situation resolves.
The answer to it does not need to be clear, and for a 6 year old boy with limitied capabilities to express himself it may be even harder. The best one to give you an answer may be a doctor who examine him carefully.
Possible reasons include physical issues like constipation or psychological issues. If the reason is a physical one training together with medication may be helpful, with psychological issues behavior or cognitive therapy may be helpful.
I do not know for sure why I pooped my pants when I was 6, but it was a psychological reason and happened in some situations; I think it was a mean to get attention and care from my parents making rewards, yellings etc (behavioristic teaching method) more of an amplifying effect rather than helping it.