Mental problems are most likely the result of evolutionary forces. As our brains evolved to develop coping mechanisms, there were tradeoffs in the process, always the risk of over or under-production of chemicals and processes that create mental imbalances, and thus far, a failure to adjust to a world that has changed considerably.
A good example of this is ADHD, which some researchers speculate is the result of traits that allowed us to be "distracted" by dangers around us and to respond quickly to those dangers. Whatever brain processes are involved, they might have gone too far in some of us, and of course, most of us no longer have the need to watch out for lions hiding somewhere, waiting to attack us.
Another example could very well be something like schizophrenia. I am not aware of any research on this topic, but I speculate that in our more primitive days, people who heard voices might very well have been treated favorably, perhaps perceived as prophets or seers, perhaps allowing a situation favorable to passing on their genes. There is certainly known to be a genetic component to schizophrenia.
In summary, mental illness is largely our brain gone awry because evolution is an imperfect process, and it is remarkable that most of us remain free of mental illness. Certainly, if one believes in a divinity with "intentions," then it does not seem inconsistent to believe that that divinity intended for us to have the wherewithal to create medications to help solve this problem.