Worldbuilding: the magical industrial revolution

There’s a short story that I can’t recall the name of about a parallel world where it has been discovered that demon raising magic can cure people of mental illness. (Who would know better the twistier bits of the human mind.)

Somehow the Church has accepted that raising demons is acceptable if it ends the curse of lunacy. I can just imagine the conclaves that went into that decision.

At the end of the story a magician forces a demon to take him to people who know how to treat the new terrible scourge of infectious diseases and he ends up in our timeline, determined to show them how to treat mental illness in gratitude for all that he is learning about the germ theory of disease.

I’m not sure though that the idea of taking historical ideas of what magic could do would be the best way to treat such a worldbuilding exercise. Those ideas were never clear and some of them were not very useful.