Death penalty is just a human way to exterminate evil people. It is serve to as warning for those who will do bad things. For it is OK because all people are aware on that law before committing a crime so it is their choice and not a fault of the law.
Death penalty serves two purposes. The first one is exactly what you had posted above. It exterminates evil people, and it scares others against doing violent and heinous crimes. The second purpose is justice. Those who commit murder and rape must pay the price.