Your Child's Best Interests
If the court must decide custody issues because you and your spouse can't reach a marital settlement agreement, the judge will consider multiple factors, not just your mental illness, to determine an arrangement that serves your child's best interests. Although these factors can vary a little by state law, judges often consider the closeness of your relationship with the child, your child's wishes if he's old enough, and whether either parent intends to remain in the marital home. Courts don't like to uproot children and force them to move just because their parents divorce, at least not if there's any way around it. The physical and mental health of each parent matters as well, but not to the exclusion of other equally-important factors. When everything is considered together, the judge will award primary physical custody to the parent in the better position to serve the best interests of the child.
Burden of Proof
In a custody dispute, the issue is not so much whether you're ill, but what effect your illness has on your child. Your spouse would have the burden of proof in a divorce trial to establish not only that you suffer from bipolar disorder, but that when you experience mood swings, it endangers your child either mentally, emotionally or physically. Your spouse – or her attorney – will typically try to establish a pattern of times when you inadvertently put your child at risk because of your illness. The diagnosis itself isn't enough; a court probably would not base a custody decision simply on your spouse's conjecture that something bad might happen someday. If you have a history of suicide attempts, however, or other extreme behavior from manic episodes, this might sway a judge into not giving you custody because you might present a danger to your child at such times.
A critical factor is whether you're receiving treatment for your condition. If you've been doing so for some time and it's been successful in minimizing or even eliminating your bipolar episodes, your spouse may not have a lot of luck convincing a judge that your child is in danger when with you. Thus, your illness is not likely to have any effect on your child and should therefore not be a consideration of the court. If you have a pattern of going off your medication, however, this could hurt you in the eyes of the court.
Mental illness adds another dimension to custody litigation that might prompt a judge to solicit the help and input of a professional. The court might order a custody evaluation as part of your divorce trial. A custody evaluation is usually performed by a licensed psychologist who will investigate your family, including your history with bipolar disorder, and give an expert opinion as to how likely it is to affect your children if you're given primary physical custody. If you've had a few bad episodes, such a professional can determine what went wrong and if it's likely to happen again. For example, maybe your doctor placed you on new medication, or there was some other trigger beyond your control that's not likely to reoccur. Custody disputes involving mental illness often end up being decided on the specific details of each individual case.