Praise be to Allah.
If stunning with a blow to the head or an electric shock kills the animal and it dies before being slaughtered properly, then it is mawqoodhah (killed by a violent blow) and it cannot be eaten even if its neck is cut after that. Allaah has forbidden it in the verse where He says (interpretation of the meaning):
“Forbidden to you (for food) are: Al‑Maytah (the dead animals — cattle — beast not slaughtered), blood, the flesh of swine, and that on which Allaah’s Name has not been mentioned while slaughtering (that which has been slaughtered as a sacrifice for others than Allaah, or has been slaughtered for idols) and that which has been killed by strangling, or by a violent blow”
The scholars of Islam are unanimously agreed that such meat is forbidden. But if it is still alive after being stunned in the manner described and is slaughtered properly, then it is permissible to eat it, because Allaah says at the end of the verse, with regard to animals that are strangled, dealt a violent blow, suffer a headlong fall, are gored by horns or partly devoured by wild beasts (interpretation of the meaning):
“unless you are able to slaughter it (before its death)”
So Allaah excludes from these forbidden types of meat those that are reached when still alive and slaughtered in the proper manner. They may be eaten because of the effect of proper slaughter, unlike those that die by being stunned before being slaughtered, in which case slaughtering does not render them permissible. Thus it is known that the Qur’aan does forbid animals that have been stunned if they die as a result of that stunning before being slaughtered properly, because the animal that is stunned has suffered a violent blow, and Allaah has stated in this verse that such an animal is haraam unless it is reached while it is still alive and slaughtered in the proper manner.
It is haraam to stun an animal by striking it or giving it an electric shock etc, because that causes suffering to the animal, and the Prophet (peace and blessings of Allaah be upon him) forbade causing suffering and tormenting them, and he enjoined kindness and goodness in general terms, and with regard to slaughter in particular. Muslim narrated from Ibn ‘Abbaas (may Allaah be pleased with him) that the Prophet (peace and blessings of Allaah be upon him) said: “Do not take anything in which there is a soul as a target.” And Muslim narrated that Jaabir ibn ‘Abd-Allaah (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) forbade tormenting any kind of animal to death. Muslim also narrated from Shaddaad ibn ‘Aws (may Allaah be pleased with him) that the Prophet (peace and blessings of Allaah be upon him) said: “Allaah has decreed kindness (or proficiency) in all things. So when you kill, kill well, and when you slaughter, slaughter well. Let one of you sharpen his blade and spare suffering to the animal he slaughters.”
If it is not easy to slaughter animals unless they have been stunned by a method that will not kill them before they are slaughtered, then it is permissible to stun them and slaughter them whilst they are still alive, in cases of necessity.