Good, competent counselling by someone who knows what they are doing will determine whether a mental illness is caused by a demon or not. Neil Anderson writes a very good book called "Finding Hope Again" which is a study on depression and the causes of it. He believes that if counselling and medication does not help a depression or mental illness, it could be a demon, but he advises wannabe exorcists not to jump in and assume that it is a demon until all other avenues are explored.
Ed Murphy, the author of "The Handbook of Spiritual Warfare" says that if a demon is present, it will manifest during the counselling process and then, and not until then, it can be dealt with.
I rate Dr Ed Murphy and Neil Anderson the foremost current authorities on deliverance because they go about it in private counselling sessions, and not with a group of untrained people trying to cast out demons at an altar call in a public church meeting.