A.F.
We had a similar situation when my now-six year old started potty training. She began to hold it because she was busy playing, caused painful stools, so she avoided going because it hurt and so the circle began. She's on Miralax (prescription, but it can be found over the counter as well) and Benefiber now to keep things soft and going, and also occasionally takes Fletcher's for Children (Castoria) to help her. She's been on meds for 3 1/2 years, with good results but weaning hasn't worked so well.
Knowing what I know now, I'd work with meds/herbs, etc to soften everything up for a bit of time before trying to potty train. The Fletcher's helps with the urge to go - and getting him going every day without holding it is pretty important. We've worked with a pediatric gastroenterologist for the 3 1/2 years our daughter has been treated for this, and we've learned more than we ever wanted to know on the subject! The year before that, our daughter was potty trained and going a week or more between stools, and screaming in pain when she finally did go.
Having run many tests, we've come to the conclusion that in our daughter's case, nothing is medically causing this, and it's simply a control issue. Giving the meds we use has sometimes taken that option away - they have to go, no choices about it. I hate it for her - she's 6 and still dealing with this. It's been a frustrating road for all involved, but she's wanting to go off the meds now and doing better than she's ever done in the past. We may have light at the end of this tunnel!
Best of luck to you! Feel free to message me if you have any questions or I can help. :)