There's nothing at all incorrect in the example sentence X and Y should have killed Z to have prevented Z from killing them. It simply means that X and Y are now dead because Z killed them. Had they killed Z, he would not have been able to kill them and they would not now be dead. If that's not the case, then the sentence is semantically incorrect but grammatically correct.
I disagree with StoneyB about this, but his substitute sentence is perfectly fine, just one of those unreal conditionals that can also be expressed as "If X and Y had killed Z [but they didn't = unreal past condition], that would have prevented Z from killing X and Y". The sentence you ask about is not a conditional but a judgment about what should have been done to prevent the killing of X and Y.
There's no difference between saying "You should have listened to my advice not to buy Apple stock to have prevented (your) losing $10,000 overnight" and "You would have had to have listened to my advice not to buy Apple stock to have prevented (your) losing $10,000 overnight".