Whenever my kitties had issues with diarrhea or constipation, it was always a medical issue.
You are on the right track to soften Gandalf's poop, but if it doesn't improve, he might need veterinary intervention.
Good luck with your baby.