Praise be to Allah.
Magic in all its forms is haram (impermissible) according to all divinely-revealed laws, and there is scholarly consensus that magic and learning magic are haram.
Magic goes against that which the Messengers brought and it opposes the purpose for which the Books were revealed.
Most of the scholars were of the view that the one who practices magic is a kafir (non-Muslim) whom the authorities are obliged to execute.
Allah says (interpretation of the meaning):
“Sulaymaan did not disbelieve, but the shayateen (devils) disbelieved, teaching men magic…”
“but neither of these two (angels) taught anyone (such things) till they had said, ‘We are for trial, so disbelieve not (by learning this magic from us)’”
This proves that magic is kufr (disbelief)
Most of the Shafi’i fuqaha (jurists) were of the view that the one who practices magic is not a kafir unless he believes that magic is permitted or he believes something like the people of Babylon believed, that practicing magic would bring them closer to the seven stars [which they used to worship].
This is subject to further debate; there is no evidence to suggest that (describing the one who practices magic as a kafir) is conditional upon his believing that to be permissible.
The correct view is that the one who practices magic is a kafir, whether he believes it to be haram or not. Simply doing magic is kufr. This is the apparent meaning of the evidence, and there are no other texts to contradict this.
Once it is proven that a person is guilty of practicing magic, then he must be killed. This was proven from a group of the sahabah (companions), but it is not for individuals to carry out this hadd (religiously prescribed) punishment without the command of the ruler or his deputy, because carrying out the hadd punishments without the authority of the ruler may lead to mischief, and destroy any sense of security in the society, and undermine the position of the ruler.