Depends on the mental illness, and the degree. I have (formally diagnosed) ADHD, which has negatively impacted my life in a number of ways including keeping jobs, but I don't get any benefits for it. I DO get PIP for my severe spinal stenosis and facet joint arthritis with a few other back issues thrown in.
Some people have anxiety so bad they physically can't go out of the house. Others decide they "have anxiety" if they feel anxious about things that almost everyone feels anxious about e.g. exam nerves, interview nerves, doing a piece of work for the first time which they aren't experienced in doing.
Same with ADHD - there are certain aspects of my behaviour I genuinely can't do anything about and don't even realise I'm doing, and if it was much worse then I would be unemployable. However some people look up stuff on line and decide that if they are sometimes forgetful, or lose their keys now & again, or get distracted when they are doing something boring, then they have ADHD (self diagnosed).
I know many Autistic people who are gainfully employed. But I've also met ones who the symptoms specific to them mean they can't function on their own and need care let alone hold down a job.
Think of it as the difference between a broken fibula (smaller bone in the lower leg) and a femur (thigh bone) shattered in 8 places by a crushing injury. One will be in a cast for about 4-6 weeks & no long term damage, the other will be physically disabled for life and possibly lose that limb or the use of it, and have attendant related problems due to being unevenly balanced e.g. back problems. Both have a broken leg, but it's a matter of degree.