Bewitchment Of Prophet Muhammad

In the name of Allah most gracious most merciful
Assalaamu alaykum wa rahmatuallahi wa barakatuhu

Bewitchment of Prophet Muhammad peace be upon him.

Magic effected prophet peace be upon him ,only as a husband,that too only on part of sexual relations.

Sahih Al-Bukhari HadithHadith 7.660 Narrated byAisha
Magic was worked on Allah's Apostle so that he used to think that he had sexual relations with his wives while he actually had not (Sufyan said: That
is the hardest kind of magic as it has such an effect). Then one day he said, "O 'Aisha do you know that Allah has instructed me concerning the
matter I asked Him about? Two men came to me and one of them sat near my head and the other sat near my feet. The one near my head asked the other,
'What is wrong with this man?' The latter replied 'He is under the effect of magic.' The first one asked, 'Who has worked magic on him?' The other
replied, 'Labid bin Al-A'sam, a man from Bani Zuraiq who was an ally of the Jews and was a hypocrite.' The first one asked, 'What material did he use?'
The other replied, 'A comb and the hair stuck to it.' The first one asked, 'Where (is that)?' The other replied, 'In a skin of pollen of a male date
palm tree kept under a stone in the well of Dharwan.' '' So the Prophet went to that well and took out those things and said, "That was the well which
was shown to me (in a dream). Its water looked like the infusion of Henna leaves and its date-palm trees looked like the heads of devils." The Prophet
added, "Then that thing was taken out." I said (to the Prophet), "Why do you not treat yourself with Nashra?" He said, "Allah has cured me; I dislike to
let evil spread among my people."

He was informed in dream about magic.
Sahih Al-Bukhari HadithHadith 4.490 Narrated byAisha
Magic was worked on the Prophet so that he began to fancy that he was doing a thing which he was not actually doing. One day he invoked (Allah) for a long period and then said, "I feel that Allah has inspired me as how to cure myself. Two persons came to me (in my dream) and sat, one by my head and the other by my feet. One of them asked the other, 'What is the ailment of this man?' The other replied, 'He has been bewitched.' The first asked, 'Who has bewitched him?' The other replied, 'Lubaid bin Al-A'sam.' The first one asked, 'What material has he used?' The other replied, 'A comb, the hair gathered on it, and the outer skin of the pollen of the male date-palm.' The first asked, 'Where is that?' The other replied, 'It is in the well of Dharwan.' " So, the Prophet went out towards the well and then returned and said to me on his return, "Its date-palms (the date-palms near the well) are like the heads of the devils." I asked, "Did you take out those things with which the magic was worked?" He said, "No, for I have been cured by Allah and I am afraid that this action may spread evil amongst the people." Later on the well was filled up with earth.

Allah subhanawatala protects Prophet from magic in his duty as prophet i.e conveying divine message & also on practising it.
52:29 Therefore proclaim thou the praises (of thy Lord): For by the Grace of thy Lord thou art no (vulgar) soothsayer nor art thou one possessed.
68:2 Thou art not by the grace of thy Lord mad or possessed.
81:22 And (O people!) your companion is not one possessed;
34:46 Say: "I do admonish you on one point: that ye do stand up before Allah--(it may be) in pairs or (it may be) singly and reflect (within yourselves): your Companion is not possessed: he is no less than a Warner to you in face of a terrible Penalty."
23:70 Or do they say "He is possessed"? Nay he has brought them the Truth but most of them hate the Truth.

Non-muslims accused him to being possessed.
His Saying : "Ye follow none other than a man bewitched" (Holy Qur’an 25:8)
“ Thou art only one of those bewitched" (Holy Qur’an 26:153)
"Tutored (by others), a man possessed" (Holy Qur’an 44:14).
"See what similes they strike for thee : but they have gone astray, and never can they find a way" (Holy Qur’an 17:48).
*As for the one who is bodily affected with some sort of a disease, following him is not prevented. Enemies of Prophets did not accuse them of bodily illness, rather of what prevents their followers from following them: that they were so bewitched that they could not realize what they say, just like lunatics. This is why God, the Exalted, says 17:48

There are various types of magic.
[a]To sow discord between man and wife.
2:102 They followed what the evil ones gave out (falsely) against the power of Solomon; the blasphemers were not Solomon but the evil ones teaching men magic and such things as came down at Babylon to the angels Harut and Marut. But neither of these taught anyone (such things) without saying: "We are only for trial so do not blaspheme." They learned from them the means to sow discord between man and wife. But they could not thus harm anyone except by Allah's permission. And they learned what harmed them not what profited them. And they knew that the buyers of (magic) would have no share in the happiness of the Hereafter. And vile was the price for which they did sell their souls if they but knew!
[b]Magic which was done on ropes & rods.
20:66 He said "Nay throw ye first!" Then behold their ropes and their rods so it seemed to him on account of their magic began to be in lively motion!

*Note:Hence there are different types of magic ,the magic which affected Prophet Muhammad peace be upon him was only on the basis of his duty as a husband.

The surah as prevention & cure from magic
113:1 Say: I seek refuge with the Lord of the Dawn
2 From the mischief of created things;
3 From the mischief of Darkness as it overspreads;
4 From the mischief of those who practice Secret Arts;
5 And from the mischief of the envious one as he practices envy.

Allah knows best.