Call me whatever you want, but I don't think Michael was ever mentally ill...at least, not in the sense most might assume. His general worldview was largely shaped by his father's harsh treatment of him during childhood, along with the insane pressure of being a young black performer in 1960s America. Even by the late '70s, he felt he still had to prove himself, because too many people associated him with his brothers and nothing else. His first attempt to counter that was co-starring in The Wiz, and then recording Off the Wall. When the latter only won a single Grammy Award, Michael felt extremely slighted because he'd poured so much of his heart in to it...and that fueled his determination regarding the production of Thriller.
Regarding his health in general, I think his medical problems began in 1984, after the accident on the Pepsi commercial set. His burns never healed completely, his pain remained constant, and his hair never grew back. As a result, he got hooked on painkillers, and things only grew worse from there. Some say that having any compulsive addiction makes you mentally unsound, but I disagree. We all have things we struggle with to various degrees, and Michael was no different. His insomnia was almost more legendary than his music - Katherine said she often caught him wandering Hayvenhurst at early hours in the morning. Others say he was crazy to go along with Evan Chandler's demands; while I'd agree it was unwise and reckless, you have to remember who Michael was and the kind of pressure he was under at the time. He thought that by settling with the family, the whole thing would be over and done with, never to be brought up again. Instead, he spent the last 16 years of his life trying to convince the world he was not a pedophile...and the American press was his worst public enemy in that regard. That's one reason why he never toured for the Invincible album, and the HIStory tour only included two U.S. dates, both in Hawaii instead of the mainland.
As for his drug dependencies, God only knows what caused him to become so intense with them. Folks still debate to this day whether Conrad Murray gave him the fatal injection, or if Michael did so himself. Personally, I have no idea, though I'd like to believe Michael's love for his kids prevented him from becoming suicidal. I just hope he's in Heaven with God & Jesus now, finally at peace like he always needed to be.