Praise be to Allah, and may peace and blessings be upon the Messenger of Allah.
It is permissible to kill snakes and serpents found outside homes. Authentic hadiths contain instructions to kill them.
As for snakes found inside homes, the Prophet ﷺ initially prohibited killing them because they might be jinn. He instructed Muslims to warn them three times. If they do not leave after being warned, it is permissible to kill them.
The Prophet ﷺ said:
"Indeed, there are inhabitants (jinn) of these houses. If you see any of them, warn them three times. If they leave, then leave them alone; otherwise, kill them."
Narrated by Muslim.
The warning means that whoever sees a snake inside their home should say:
"I warn you, O snake, not to appear before us or harm us."
Ibn Abd al-Barr mentioned that the warning concerning snakes found inside homes applies in Madinah and elsewhere, whereas snakes found in deserts may be killed without prior warning.
As for the belief that killing a jinni appearing in the form of a snake brings bad luck or misfortune, this is a false belief with no basis in Islamic law.
Conclusion:
It is permissible to kill snakes and serpents found outside homes.
Snakes found inside homes should be warned three times before being killed. If they do not leave, killing them is permissible.
It is incorrect to believe that killing them brings bad luck or misfortune.
And Allah knows best.