Our son wasn't comfortable using the toilet consistently until he was nearly 5. Some children aren't. And some regress when overtired, overstimulated, pre-occupied or stressed (new baby in the house). Ds had a physical just before his 5th birthday and was still wearing diapers per his preference. Our doctor was fully informed that boys are toileting independent much later than girls.
Per a quick search on the internet, I found that the most common source of inability to control the bladder to be related to allergies. Evidently, 50% of children who eliminated cow dairy became more toileting abled. The other most allergenic foods were chocolate, eggs, citrus fruits, and wheat. I saw that bed wetting (enuresis) is highly hereditary. If both parents had issues, than 77% of their children have issues with inability to control the bladder. If only one parent, than 44% of children had issues.
Apparently 20% of 5 year olds are not fully toileting. 14% of 7 year olds are not; 4% of 12 year olds; and 1-2% of 15 year olds are not fully toileting. Nighttime control is most difficult, especially for boys and for those who sleep deeply. Avoiding liquids after 6pm appears to help. Indication for medical intervention is not typically recommended until age 6 or 7. However most children who are not toileting independently at 6, won't be at 7. Most concerns were related to urinary tract infections, diabetes and neurological issues.