The rise of the lunatic asylum and its gradual transformation into, and eventual replacement by, the modern psychiatric hospital, explains the rise of organized, institutional psychiatry. While there were earlier institutions that housed the 'insane', the conclusion that institutionalisation was the correct solution to treating people considered to be "mad" was part of a social process in the nineteenth century that began to seek solutions outside families and local communities.
To illustrate this with one regional example, in England at the beginning of the nineteenth century, there were, perhaps, a few thousand "lunatics" housed in a variety of disparate institutions but by the beginning of the twentieth century, that figure had grown to about 100,000. This growth coincided with the development of alienism, now known as psychiatry, as a medical specialty.
In the Islamic world, the Bimaristans were described by European travelers, who wrote about their wonder at the care and kindness shown to lunatics. In 872, Ahmad ibn Tulun built a hospital in Cairo that provided care to the insane, which included music therapy. Nonetheless, medical historian Roy Porter cautions against idealising the role of hospitals generally in medieval Islam, stating that "They were a drop in the ocean for the vast population that they had to serve, and their true function lay in highlighting ideals of compassion and bringing together the activities of the medical profession."
In Europe during the medieval era, the small subsection of the population of the mad who were housed in institutional settings were held in a variety of settings. Porter gives examples of such locales where some of the insane were cared for, such as in monasteries. A few towns had towers where madmen were kept (called Narrentürme in German, or "fools' towers"). The ancient Parisian hospital Hôtel-Dieu also had a small number of cells set aside for lunatics, whilst the town of Elbing boasted a madhouse, the Tollhaus, attached to the Teutonic Knights' hospital.Dave Sheppard's Development of Mental Health Law and Practice begins in 1285 with a case that linked "the instigation of the devil" with being "frantic and mad".