Hiya I answered a [similar question] (https://www.reddit.com/r/AskHistorians/comments/3fc4uj/when_were_the_first_psychiatric_asylums/ctp0fu7) to yours a few weeks ago, it was a little more broad in the area the user was interested in however I would think a lot of it is still applicable. I'll post the relevant sections below (please note that I'm not a Historian of the Mediterranean):
...Psychiatry itself was fairly unscientific with it dating back to the ancient greeks. Psychiatry in the Greeks mind was the field of the spiritualists & that of the supernatural with exorcisms being commonplace, this was the definition of Psychiatry until the mid 19th century when it started to be recognised as a medical discipline & not just a subsidiary of Philosophy.
However there were some people that thought those with mental illness should be treated in a humane way (even if their theories as to what was causing their distress & how best to cure it was distorted by the limitations of the age) This "humane treatment" does date back to the greeks & romans but I will say that I'm not too familiar with their methods so I can't go too in depth:
In the 4th Century BC, No other than Hippocrates:
"theorized that physiological abnormalities were causing mental disorders. He viewed the brain as the seat of consciousness, emotion, intelligence, wisdom and reasoned that disorders involving these functions must be located in the brain and were not inflicted by the Gods"
And in 129 BC, Greek physician Asclepiades advocated humane treatment of the mentally ill, he freed them from confinement & gave a prescription of diets & massages. Roman physician, Galen;
"adopted a single symptom approach rather than broad diagnostic categories, for example studying separate states of sadness, excitement, confusion and memory loss. Galen extended these ideas and developed a powerful and influential school of thought within the biological tradition that extended well into the 18th century."
[In this next bit I talk about medieval Iraq, specifically Baghdad but i'm sure it can be applied to 8th century "Al-Andulus" (Islamic Spain and Portugal) as well]
Skipping gleefully forward into 8th Century Baghdad, we see some of the first psychiatric hospitals. These hospitals were humane as muslims believed the mentally ill were incapable of doing things yet deserving of treatment. You can see here in this painting of a Muslim doctor treating a mentally ill patient. This treatment can be linked to the Islamic belief of "Greater Jihad" (أكبر الجهاد; al-jihad al-akbar), Whereas "Lesser Jihad" (الجهاد الأصغر; al-jihad al-asghar) is an outer physical struggle against the enemies of Islam, Greater Jihad is the struggle against oneself.
[After this point, I move the audiences' focus to the 19th Century and beyond as this is what I'm most comfortable with, so I won't post that part of the answer. However if you're interested in reading about that I've posted a link to the original answer in full, above. I will post some of the sources i used relating specifically to the medieval section]
...Further Reading:
Penguin Classics' "Hippocratic Writings"
Jacques Jouanna's "Hippocrates"
Michael Bonner's "Jihad in Islamic History: Doctrines and Practice"
Al-Khatib al-Baghdadi's "A History of Baghdad"
[...] If you have any other questions, please don't hesitate to ask :)