My DS5 has this problem. We actual had to see a specialist about this. Some days I think I will never get him trained. He stays clean at school all day. Anyway his doctor told me this started when he was a baby because of the pain from being constipated caused him to start holding it in so it would to hurt him. From holding it in so much he has enlarged his colon/rectum and really does not know when he has to go poop. He told me it could take up to a year for everything to go back to normal size and for him to be able to feel the urge to actually go poop on his own. He is on medicine daily to loosen his bowels so that he cannot hold it in.
This has been very frustrating for all concerned. Everytime we start making a breakthrough his birth mom gets him for a 1-2 day visit and we have had to start all over. So I told her after this last doctor visit that he could not go spend the night with anyone until he is fully and totally potty trained and that the doctor told me it could take up to a year. She acted like it was no big deal for her.
So I sure have no words of wisdom on this front.