It is known that several ayat in the Quran spoke about magic, for example in Sura Al-Baqara [2:102]
How does Islam view magic?
And what is the ruling on learning magic in Islam?
Learning, practicing and teaching magic, all of them, is kufr (disbelief).
Allah says in Qur'an:
And they followed [instead] what the devils had recited during the reign of Solomon. It was not Solomon who disbelieved, but the devils disbelieved, teaching people magic and that which was revealed to the two angels at Babylon, Harut and Marut. But the two angels do not teach anyone unless they say, "We are a trial, so do not disbelieve [by practicing 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 . And the people learn what harms them and does not benefit them. But the Children of Israel certainly knew that whoever purchased the magic would not have in the Hereafter any share. And wretched is that for which they sold themselves, if they only knew. [Surah Al-Baqarah 2:102]
Abu Ja'far Ar-Razi said that Ar-Rabi' bin Anas said that Qays bin 'Abbad said that Ibn 'Abbas said, "When someone came to the angels to learn magic, they would discourage him and say to him, 'We are only a test, so do not fall into disbelief.' They had knowledge of what is good and evil and what constitutes belief or disbelief, and they thus knew that magic is a form of disbelief. When the person who came to learn magic still insisted on learning it, they commanded him to go to such and such place, where if he went, Satan would meet him and teach him magic. When this man would learn magic, the light (of faith) would depart him, and he would see it shining (and flying away) in the sky. He would then proclaim, 'O my sorrow! Woe unto me! What should I do.''
Al-Hasan Al-Basri said that this Ayah means, "The angels were sent with magic, so that the people whom Allah willed would be tried and tested. Allah made them promise that they would not teach anyone until first proclaiming, "We are a test for you, do not fall into disbelief.''' It was recorded by Ibn Abi Hatim.
Also, Qatadah said, "Allah took their covenant to not teach anyone magic until they said, "We are a test. Therefore, do not fall in disbelief.'''
Also, As-Suddi said,
"When a man would come to the two angels they would advise him, 'Do not fall into disbelief. We are a test. ' When the man would ignore their advice, they would say, 'Go to that pile of ashes and urinate on it.' When he would urinate on the ashes, a light, meaning the light of faith, would depart from him and would shine until it entered heaven. Then something black that appeared to be smoke would descend and enter his ears and the rest of his body, and this is Allah's anger. When he told the angels what happened, they would teach him magic.
So Allah's statement,
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).
Sunayd said that Hajjaj said that Ibn Jurayj commented on this Ayah (2:102),
"No one dares practice magic except a disbeliever. As for the Fitnah, it involves trials and freedom of choice.''
The scholars who stated that learning magic is disbelief relied on this Ayah for evidence. They also mentioned the Hadith that Abu Bakr Al-Bazzar recorded from `Abdullah, which states,
Whoever came to a soothsayer or a sorcerer and believed in what he said, will have disbelieved in what Allah revealed to Muhammad .
This Hadith has an authentic chain of narration and there are other Hadiths which support it.
Abu Hurairah (May Allah be pleased with him) said:
The Prophet (sallallaahu ’alayhi wa sallam) said, "Avoid the seven destructive things.'' It was asked: (by those present): "What are they, O Messenger of Allah?'' He replied, "Associating anyone or anything with Allah in worship; practising sorcery, killing of someone without a just cause whom Allah has forbidden, devouring the property of an orphan, eating of usury, fleeing from the battlefield and slandering chaste women who never even think of anything touching chastity and are good believers.'' [Al-Bukhari and Muslim].
All the acts mentioned in this Hadith are unlawful. The teaching, learning and practising of magic are all unlawful, and Imam An-Nawawi has quoted this Hadith here to prove the prohibition of magic in Islam.
And there are people who quote a hadith to learn magic : "Learn magic but do not practice it" is not a sound Hadith. It is false and has no basis. This Hadith has no basis and the correct view of scholars is that one is not allowed to learn magic or act according to it. Rather, one should beware of that, because learning magic and teaching it are disbelief.
This is the view of the Sunni Muslim scholars.
No. Learning and practicing magic is not prohibited except for doing a mischief. The magic performed by Jews on Muhammad was countered by another magic that is opening the knots of the hairy stuff found in a well. The Sufis type branches have this opinion. Grand Mufti of Pakistan MuniburRahman says so.