I went to a gastrointestinal specialist for my daughter regarding constipation. Usually constipation is only because of any three of the following reasons. One, your baby is constipated because of his diet. Two, because he has a slow digestive tract. Or three, there is physically something wrong with his anus/colon/intestines, etc.
The third can easily be ruled out in your case because if he was born with a physical issue, his constipation would have started the day he was born, not at 5 months.
If your baby is formula fed then most likely he is constipated because of his diet. That is a normal occurrence for many, and most people "cure" it by giving a little watered down prune juice daily, or by making your own "formula". There is a great recipe on Mercola.com.
If your baby is breastfed, the doctor will tell you it isn't possible for him to be constipated. I was told that over and over, but my baby was exclusively breastfed and still extremely constipated. Finally, with a lot of research and doctor visits I realized my daughter just had a slow digestive tract. The longer the milk was in her colon, the more water her body took from it and the dryer her poop was. I started helping her with prescribed GlycoLax, which helped keep more water in the colon and lower intestines. It worked, but was habit forming. I then weened her to prune juice and made sure she had a lot of water to drink daily, and avoided rice cereal as it really plugs up the intestines. But what really worked (permanently) is taking her to a Foot Zonologist (basically is foot reflexology) to clear her whole system, including her lymphatic system, working and flowing properly. Now she is no longer constipated.
I hope that helps. :-) Good luck!