Wa alaikum assalam wa rehmatullahi wa barakatuh...
We drs sometimes go for removing the whole organ or the limb, if someone is suffering from malignant cancer, the cancer which spreads...
This is mercy for that man and that body...The life is saved, the person would not suffer from further pain and distress, the body is saved from the malignant deposits...(sec carcinoma)
Similarly, when there is a sin , which would destroy the whole society and takes many lives,if it prevails in that society,it should be wiped off at once...
This is mercy too