My grandson was chronically constipated after months of regular soft shaped movements. The doctor could find no reason for this to have happened. As babies/children mature their body changes and this, for my grandson, is how it changed.
We focused on doing those things that deal with constipation. Made sure he had more than an adequate amount of fiber in his diet. Stopped giving him foods that cause constipation such as milk and cheese. His diet consisted of lots of fresh fruits and vegetables, increased liquids, and whole grains. He did have some cheese because he loved it but only a very limited amount.
Eventually the doctor prescribed Miralax which is not a laxative. It's a natural product that absorbs moisture into the intestines. It helps the body naturally get rid of wastes and is not habit forming. Miralax is now sold over the counter and you could give that a try if increasing fiber and liquids don't help.
Keep in mind that since his bowel movements are painful he may avoid having them. Take him to the toilet after meals when most of us naturally have a bowel movement or at times that you remember him having had movements. Don't force him to stay until he has one. Just give him the opportunity.
He's old enough for you to talk with him about what is happening. Use a reassuring voice. Explain to him that he needs extra fiber and liquids to get his system going again. Let him know that even tho it may be painful it's important to go so that he won't get sick. Stay with him. Be calm and reassuring. If he thinks you're concerned he'll be more tense and less apt to have a bowel movement.
My grandson is now 6 and has had "normal" bowel movements for several years now.