Sanhedrin Chapter 9, Mishnah 2. The Mishnah comes to emphasize a fundamental point: for a person to be liable to the death penalty by the court for murder, he must intend to kill someone for whose murder one is liable to death, and he must land a blow that is capable of killing - so that the death can be attributed exclusively to the act and intention of the murderer.
Intended to Kill This One and Killed That One:
Reuven goes out to hunt, aims his weapon at a lion, and Shimon is standing nearby. Even if witnesses warn him: "Do not shoot at the lion, Shimon is standing there," and he answers: "I am not shooting at Shimon," and despite their warning he shoots and kills Shimon - he is exempt, since he did not intend to kill Shimon but to shoot the animal.
"Nitkavein laharog et habeheimah veharag et ha'adam" - intended to kill the animal and killed the person - he aimed at the animal and hit a person.
"L'oved kochavim veharag et Yisrael" - an idolater and he killed a Jew - he intended to kill a non-Jew, for whose murder one is not liable to death, and mistakenly hit a Jew.
"Lenefalim veharag ben kayama" - non-viable premature babies and he killed a viable baby - he intended to kill a nefel, meaning a baby born unable to live on its own: it was born with some defect and cannot survive thirty days, and its death is certain and only a matter of time. By mistake, he ended up killing the healthy, viable baby.
In all these cases - "patur" - he is exempt, since he did not intend to kill someone for whose murder one is liable to death.
When the Blow Landed in a Different Place Than Intended:
"Nitkavein lehakoto al motnav velo hayah bah kedei lehamit al motnav, vehalchah lah al libo vehayah bah kedei lehamit al libo, vamet - patur" - intended to strike him on his loins and it did not have enough force to kill on his loins, but it went to his heart and it did have enough force to kill on his heart, and he died, he is exempt - Reuven intended to strike Shimon on his loins (the 'loins' being the area of the body connecting the leg to the torso), and this blow was not capable of killing. However, the blow missed the thigh and hit his heart, and there it indeed had enough force to kill, and Shimon died. Reuven is exempt, since he did not intend to land a lethal blow but rather to strike his leg, and a mistake occurred.
"Nitkavein lehakoto al libo vehayah bah kedei lehamit al libo, vehalchah lah al motnav velo hayah bah kedei lehamit, vamet - patur" - intended to strike him on his heart and it had enough force to kill on his heart, but it went to his loins and did not have enough force to kill, and he died, he is exempt - Reuven intended to stab Shimon in his heart, and had the dagger reached the heart as he aimed, Shimon would have died. However, he missed, and the dagger penetrated his thigh, and on the loins such a wound is not capable of killing. Even though Shimon ultimately died - he is exempt: a stab to the thigh is not lethal, and it stands to reason that he died from a further complication, such as an infection that developed in the wound. Thus, the stab together with the infection are what killed him, and not Reuven's stab in itself. Reuven is certainly a bad person, but he is exempt from execution.
Adult and Child:
"Nitkavein lehakot et hagadol velo hayah bah kedei lehamit et hagadol, vehalchah lah al hakatan vehayah bah kedei lehamit et hakatan, vamet - patur" - intended to strike an adult and it did not have enough force to kill the adult, but it went to a child and it had enough force to kill the child, and he died, he is exempt - Reuven swings a club at Shimon who is a large adult, and this swing is not capable of killing him. Shimon ducks, and the blow hits Levi, who is smaller than him, and for whom it is capable of killing, and Levi dies. Reuven is exempt, since he intended to strike Shimon a non-lethal blow, and only due to a mistake did the blow land on Levi.
"Nitkavein lehakot et hakatan vehayah bah kedei lehamit et hakatan, vehalchah lah al hagadol velo hayah bah kedei lehamit et hagadol, vamet - patur" - intended to strike a child and it had enough force to kill the child, but it went to an adult and it did not have enough force to kill the adult, and he died, he is exempt - Reuven swung the club at little Levi and intended to kill him, and indeed it was capable of killing him. Levi ducked, and the blow hit the large Shimon, for whom it is not capable of killing, and nevertheless an unusual thing happened and Shimon died. Reuven is exempt, since his act is not among those things that would kill Shimon, and his death came from a combination of factors - not from the blow of the club alone, but from an additional thing that is not Reuven's direct action.
Cases Where He is Liable:
"Nitkaven lehakoto al motnav vehayah bah kedei lehamit al motnav, vehalchah lah al libo vemet - chayav" - if Reuven struck Shimon with a sword on his waist, and such a blow is capable of severing the femoral artery and is therefore a lethal blow. Shimon moved, and the sword struck his heart, and Shimon died. Reuven is liable, since he is a murderer: he intended to deliver a lethal blow and to kill Shimon, and indeed he aimed at the waist, but the blow struck the heart and Shimon died just as he intended. He intended to murder, tried to murder, and actually did murder, and there is no practical difference that the blow landed on the heart rather than the waist.
"Nitkaven lehakot et hagadol vehayah bah kedei lehamit et hagadol, vehalchah lah al hakatan vemet - chayav" - if Reuven wanted to kill Shimon the adult and crush his head with a club, and such a blow would indeed have killed him. Shimon ducked, and the club struck the head of Levi, who was smaller than him - and if it was capable of killing the adult, all the more so is it capable of killing the child - and Levi died. Reuven is liable: he intended to deliver a lethal blow and kill a person, and indeed he killed, and the one killed is a Jew.
The view of Rabbi Shimon:
Rabbi Shimon disagrees and holds: "Afilu nitkaven laharog et zeh veharag et zeh - patur" - even if he intended to kill this one and killed that one, he is exempt. According to him, Reuven tried to kill Shimon and did not kill him, but rather killed Levi. Even though Reuven is a terrible person and a potential murderer, the act he performed in killing Levi is not the act he intended, and therefore he is technically exempt from execution by a human court. At the hands of Heaven he will certainly be punished, but at the hands of man he is exempt from the death penalty.
And it seems that the Rambam rules here in accordance with Rabbi Shimon: one who intends to kill so-and-so and kills someone else - at the hands of Heaven he is a murderer and there is no doubt about the matter, but regarding his liability here below, since the warning was not a certain warning regarding the correct person and the like, he is exempt from the death penalty.
In summary: Our Mishnah establishes two conditions for liability to the death penalty for murder: intent to kill a person for whose killing one is liable to the death penalty, and a blow that is capable of killing. Therefore, one who intends to kill an animal, an idolater, or a non-viable fetus, and killed a viable Jew - he is exempt; and similarly, one who intends to strike a blow that is not capable of killing and killed - he is exempt, since the death is not attributed solely to his act and his intent. However, one who intends to deliver a lethal blow and killed - he is liable, while according to the view of Rabbi Shimon he is exempt even in this case, since he intended to kill this one and killed that one, and it seems that the Rambam ruled likewise.