This is a very open-ended general question, but I will try to answer it as best as I can. In custody proceedings the mental health of a potential custodian can certainly be relevant information in deciding with whom to place the child. Generally, a law guardian will be appointed and issue a report to the court after doing home visits at the homes of each of the prospective custodians. If your ex-wife is unable to safely raise the children due to her illness, those "deficieincies" or problems will be pointed out in the report. If your children are old enough to express a preference and explain the preference, a court will also take that into consideration, though a child's preference may not be automatically accepted. The fact that you are a nuturing parent will defineitely be in your favor, but the court will make the decision based on what is in "the best interests of the child."
Sign up to receive a 3-part series of useful information and advice about child custody law.