There is a precedent. I don't have the citation right now. This happend in case of a Jain Monk renouncinfg world as a child.some of the wll known Jain priets were from other community. The summary of those decision is :
1. Welfare of the cahild is paramount
2. faith can not be imposed on the child
3. If child has independent thinking ability view of the child will be taken into account.
Simlar precednts are more or less use in the case odf custody of a child to estranged parents. As a normal rule mother gets the custody of an infant . But execlptions are made keeping the above principles in mind/