Benefiting Creation, Even through Necessary Harms
Imām Ibn Taimiyyah, may Allāh have mercy on him, said:
The religion and [Islamic] law have not commanded other than what is beneficial, good, and merciful for the slaves [of Allāh]; it is upon a believer to intend that and want that, so his intent should be to do good to creation and benefit them [seeking Allāh’s pleasure by doing that]. And if that were not attainable without causing some harm to come to some of them,¹ he is to do that upon an intention of preventing, through [that harm], that which is worse or more evil than that; or of attaining, through [that harm], that which is more beneficial than [would be attainable] without it.
¹e.g., Islamic punishments, parents punishing children, doctors giving necessary, but unpleasant treatments, and other necessary harms slaves of Allāh are obligated to carry out upon others. (tr., from the original context)
Jāmiʿ Al-Masāʾil, vol. 6, pp. 37-8.