In the reign of Prophet Sulaiman علیه سلام, Bani Isra’el started practicing Magic. At this Sulaiman علیه سلام tried to stop them. He took their books & buried them under his holy chair.
After the death of Sulaiman علیه سلام, rogues took those books (of magic) out of soil & said to the people that Sulaiman علیه سلام ran his kingship with the help of these books.
The pious & learnt men of Bani Isra’el though opposed this but commoners took magic as knowledge of Hazrat Sulaiman علیه سلام. This practice remained till the coming of Muhammad صل الله علیه وسلم.
A Verse of Surah Al Baqarah was alighted in the negation of this practice, which is as follows:
“And they followed [instead] what the devils had recited during the reign of Sulaiman علیه سلام. It was not
Sulaiman علیه سلام. who disbelieved, but the devils disbelieved, teaching people magic and that which was revealed to the two angels at Babylon, Harut & Marut But the two angels do not teach anyone unless they say, “We are a trial, so do not disbelieve [by practising magic].” And [yet] they learn from them that by which they cause separation between a man and his wife. But they do not harm anyone through it except by permission of Allah عزوجل. & the people learn what harms them and does not benefit them. But the Children of Bani Isra’el certainly knew that whoever purchased the magic would not have in the Hereafter any share. & wretched is that for which they sold themselves, if they only knew.” [Al Qur’an 2:102]
Hence practicing Magic is heresy (کفر) in Islam & one doing so will be pagan.
Any mistake, on my part, if found, may please be forgiven.