I have had patients with serious mental illness get custody of their children
even when the other didn't have mental illness.
They must prove that they are the better parent. This includes regular psychiatric treatment and compliance with medications. It also depends upon what the other parent is like.