In the case of a female, the mother has this right of custody until she reaches puberty. This has been declared at nine years of age. (al-Mawsili, al-Ikhtiyar li ta'lil al-mukhtar, 3/237)
The right of custody will be taken away from the mother if she:
1.Leaves Islam,
2.Openly indulges in sins such as adultery and there is a fear of the child being affected,
3.She does not attend to the child due to her leaving the house very often,
4.She marries a non-relative (stranger) to the child by which the child may be affected,
5.She demands payment for the upbringing of the child if there is another woman to raise the child without remuneration.