Killing dogs or pigs is not necessary, they should be treated like all other animals.
“Prophet Muhammad (peace and blessings of Allah be upon him) has ordered the killing of certain dogs, and there are related narratives in the books of Hadith that confirm this. However, in some of these stories, there are expressions that exempt or prohibit the subsequent killing of dogs. Therefore, it is understood that this order must be related to dogs that attack and bite or have rabies. ” (Diyanat Islam Encyclopedia, art. Dog ).
The following information is from the annotations of Sahih Muslim: “According to our researchers, the dog is killed if it has rabies. Otherwise, it is not allowed to kill him. In this regard, it is equivalent if the dog was useful or not.”
There is the following hadith in Sahih Bukhari, in the Book of “Penalty of Hunting while on Pilgrimage”:
Narrated Hafsa: “Allah’s Messenger (pbuh) said, “It is not sinful (of a Muhrim) to kill five kinds of animals, namely: the crow, the kite, the mouse, the scorpion and the rabid dog.” (Reference : Sahih al-Bukhari 1828 ; In-book reference : Book 28, Hadith 8″
It is certain that God’s Messenger (pbuh) had once ordered to kill a dog, but it is as genuine as he did not order to kill the dogs afterwards. Considering the information above, we see that only dogs that had rabies could be killed. We cannot generalize this to kill all the dogs.
Besides, the hadith is related to the penalty of killing an animal while in the state of ihram. It is known that hunting an animal in the state of ihram requires expiation (al-Maidah 5:95). The hadith does not order to kill the dogs, but it informs that the pilgrims in the state of ihram shall not be sinful if they kill one of these animals. All of these animals may injure the person, and even cause one’s death. Therefore, they will not have to expiate for it.