Well, consider what happens in surgery; people get cut open in order to feel better later. That's harming someone in order to heal them. Chemotherapy is a similar idea; you poison people in order to get rid of the cancer. They feel terrible, but get better.
In my previous campaign there was a cleric of Kossuth whose magical healings were accompanied by pain, as if by burning. He was the only cleric in the city who could cast raise dead but nobody ever asked for the service on behalf of deceased loved ones. The reason- because it felt like being burned alive, only in reverse. It is no great stretch of the imagination to suppose that healing spells granted by evil deities might feel terrible; so might spells cast by deities with domains like war or purification.
The painful healing spells put some game mechanics behind elements which might be present for flavor reasons. It provides ingame reasons why people might prefer natural healing to the magical variety, and also follows the real world precedent of surgery and chemo that healing sometimes requires hurting. So that's three logical reasons why these spells might exist.