Even after a decade of international funding and medical expertise pouring into Afghanistan, many locals still believe that the grim ordeal at the shrine will cure mental health problems -- or as they see it, possession by malevolent "jinn" spirits.
"I had a big argument with my father," said Muhammed, a thin young man sitting on a dirty blanket with heavy chains around his ankles and wrists. "I took money from him to buy a motorbike.
"I am very unhappy and I am angry at him that he put me here."
Muhammed, who says he has five war wounds after serving in the Afghan army, is incarcerated in a row of 20 miserable stone cells.
The ceilings are low and damp, and there are no fans in the summer or heating in the winter.
"The patient is kept in chains for 40 days on a diet of bread with black pepper," said Malik, the shrine supervisor.
"He is given this to make bad spirits go away. When someone is infected by ghosts, we read verses of the Koran, and married women without children give them amulets to make the spirits depart."
"It has been the same for 360 years, and thousands of people have been cured."
At the end of the course, the "patients" are given broth made from goat's head to complete the cleansing process.
Those undergoing the gruelling regime appear in fast-deteriorating health and barely able to talk due to exhaustion.
"I did not want to come, my brother forced me," said Abdul, in his 30s, in a weak voice, unable to explain why he was sent to the shrine.
"They told me they would take me to a doctor and they took 5,000 Afghanis ($90) from my pocket for that. I feel dizzy and have headaches."
Abdul's cell stinks of sweat and urine, and it is littered with trash and soiled linen. Children approach the cell to mock him, before running away laughing as he shakes in desperation.
Shah Temor Mosamim, a doctor and director of a psychiatric hospital in Kabul, dismissed the shrine's treatment as "having no basis in scientific fact".
"No matter how aggressive a patient is, if you don't give him much food for 40 days, he will get quieter," Mosamim said.
"In Afghanistan, there have been these traditional ways of treatment for mental patients -- chaining them up in rooms or shrines. In some cases, patients are suffering from depression or mental problems."
The campaign group Human Rights Watch has called for the Mia Ali Baba shrine, named after a 17th-century holy man, to be closed and there is also concern from local rights activists.
"This place should be shut down as its practices are not compatible with human rights," said HRW researcher Heather Barr.
"Mental health treatment is at its basic stages in Afghanistan and unfortunately has not been a high priority for international donors in spite of the fact that many Afghans have experiences of serious trauma."
Rafiullah Bidar, of the Afghanistan Independent Human Rights Commission, described how families leave patients to live in appalling conditions at the shrine.
"They think that it is the last option... we cannot ignore it," he said. "These families are not satisfied with government medical services, that is why they rely on the shrine.
"The environment that the patients live in is unhealthy, they defecate and urinate in their cells. I remember the stench and filthy environment when I visited."
For Muhammed and Abdul, the greatest fear is that they have been incarcerated not to be cured -- but to die.
From their cells, they can see the rough graves of those who never left.
"Some families do not come back for the sick who remain for six or eight months and sometimes die," said caretaker Mir Shafiqullah. "We bury them here."