Some criminals are so bad that the only punishment for them is death. At least, this is the view seemingly endorsed by the Harry Potter universe – which is otherwise pretty liberal in its worldview.
Bellatrix Lestrange is locked up in Azkaban, the most fearsome of all wizard prisons, for her role in torturing Neville Longbottom’s parents Frank and Alice (presumably she committed a bunch of other crimes during Voldemort’s first reign of terror, too). Several years later, turncoat Dementors break Bellatrix out of Azkaban; when she escapes, she’s still loyal to Voldemort, and still determined to bring down the wizard/Muggle status quo.
So basically, her time in prison hasn’t rehabilited her even a bit. It hasn’t deterred her from committing future crimes. Nor has it ultimately deprived her of anything: she comes out of Azkaban and instantly resumes her magical power and position at Voldemort’s right hand. Bellatrix demonstrates the failure of incarceration as a means of punishment. The only way for society to deal with criminals of this nature, then, is to execute them, and Molly Weasley comes Bellatrix’s executioner during the Battle of Hogwarts.
And, of course, there’s Voldemort himself. Through the series Harry knows that at some point he’ll have to defeat Voldemort – and it’s made clear, first implicitly and later explicitly, that “defeat” actually means “kill”. It’s not like Voldemort can be locked up in a tower for the rest of his life, Grindelwald-style (though Deathly Hallows hints that Grindelwald eventually felt remorse for his crimes, suggesting rehabilitation does work in some circumstances). The only punishment suitable for the Dark Lord is death, and while Harry technically doesn’t kill Voldemort, Voldemort does end up dead.