So, this is only true in a limited set of circumstances. If the public doesn't have faith that death is always (or almost always) given justly, then it doesn't work as a deterrent. It's like having an unpredictable abusive parent, stern parenting helps a child know how they should behave, erratic unpredictable abuse doesn't teach anything. If a person knows they could wind up punished for nothing accidentally, or knows they could get away with it, it won't act as a deterrent anymore, they won't take the deterrent into account when making decisions because the result is unpredictable. Second, the deterrent only applies to a subset of people who are opportunistic predators behaving rationally. There is another subset of people who, either because they're unstable or because they enjoy it, will prey on those around them. These people must be removed, nothing will deter them, a group has a right to protect itself from them.