Your original question is what recourse you might have.
It's a tough situation because (1) California is an employment-at-will state, (2) you were subject to a contract term, and (3) your health issues appear to have impaired your ability to function in your job.
Generally speaking, California is an employment-at-will state, which means that an employer or employee can terminate the employment relationship at most any time and for most any reason. There are exceptions; for example, an employer cannot terminate an employee based on their disability (including most mental health issues), but that only applies to situations where the employee can perform their work with reasonable accommodations.
Employment contacts work a bit differently. The employer and the employee can contract around the employment-at-will doctrine, within certain confines. The employer is still prohibited from engaging in illegal forms of discrimination
(e.g. disability), however it generally shifts the issue away from the employment doctrine and toward an Americans with Disabilities Act issue. In other words, if an employer contracts with a new person because it was discovered that the first person assigned to the job suffered from bipolar disorder, and if that disorder (if reasonably accommodated) would not interfere with the first person's ability to perform the task, that would typically be enough to run afoul of the ADA
The first concern that I would have for your case is that I am not confident, based on the information presented, that reasonable accommodations would allow you to perform your work at the standard required of the job. You can evaluate for yourself if that is the case.
The second concern is evidentiary. Even if reasonable accommodations would allow you to perform the job, those accommodations would have to be declined upon request or you would have to prove that, more like than not, you were declined for reinstatement due to the discovery of your disability.
So it has a lot of challenges. It's not that the law won't protect someone suffering from these sorts of mental health issues, but the reach of that protection is somewhat limited.
I understand that you may have follow-up questions. Let me know if I may be of further assistance. Thank you.