Is it possible to have a mental illness and have capacity?

Yes, the two things are very different. In fact, it is very common for people to have a mental health diagnosis and have capacity to make decisions.