The "islamic golden age" (8th-13th centuries AD) seemed to be a really compassionate and caring time for the mentally ill as I briefly described in this answer:
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.
Now on to your specific question. Please note that I don't know an awful lot about this time period so my knowledge goes as far as the sources I've managed to find
It is said the islamic hospital was one of the golden ages' greatest achievements. The Persian word for "hospital" was bimaristan a compound of the words bismar- ('ill person') and -stan ('place'). The Cairo asylum was opened in 872 (as you say) by Ahmad ibn Tulun, the Abbasid governor of Egypt.
According to psychiatrist, Harold G Koenig, even though the first hospital solely dedicated to psychiatry was built in 872, the most famous one was built in 1283, it was open for use to all whether you be rich, poor etc. They had wings for specific mental illnesses, a mosque and a chapel. Koenig also states that during the 'al andalus' era of Spain, Muslims also set up another asylum in Granada in 1365.
According to Michael W. Dols, the reason mentally ill people were hospitalised instead of fending for themselves was because Muslim doctors considered it an actual 'medical condition' (contrary to popular belief that it was just demons). Islamic leaders supported this 'groundbreaking' idea because they thought it would fulfill their religious obligation to charity.
Contrary to Greek & Roman ideas of mental illness (which you can read about in my linked post), Muslim doctors wanted to find alternative methods, to which they did. Ihsan-Al-Issa states that Al-Razi (dubbed the 'father of islamic psychiatry') was one of the first to write that these illnesses be down to 'nervous breakdowns or other problems of the mind'.
In his tome Continens, Al-Razi supposedly devotes a whole chapter to melancholy, it's symptoms and ways of treating it. Al-Razi supposedly also talked of the benefits of psychotherapy (Al Ilaj Annafsani) and other things such as 'clinical lycanthropy' (a delusion in which one thinks they are a werewolf).
During this time some mental illnesses were redefined and some were merely classed as "holy fools" or "wise fools" not lunatics.
Hopefully this helped!
Sources and Further reading:
Koenig. G. H (2005); "Faith and Mental Health: Religious Resources for Healing"
Porter. R (1997): "The Greatest Benefit to Mankind: A Medical History of Humanity"
Dols. W. M. (1992); "Majnūn: The Madman in Medieval Islamic Society"
Al-Issa. I (2000); "Mental Illnesses in Medieval Societies"
Al-Razi. Z. i. M. (Date Unknown); "The Virtuous Life, Continens Liber"