When witchcraft was used against the Prophet , this did not affect his worship
Question

How was witchcraft used against the Prophet (peace and blessings of Allaah be upon him) when he was the one whom no one could match in worship?
Praise be to Allah.The correct view is that the Prophet (peace and blessings of Allaah be upon him) was not harmed by that withcraft physically, mentally or spiritually, or with regard to the Message which he had been enjoined to convey. None of the people noticed or mentioned any change in his life or in his dealing with them, his salaah and adhkaar, or his teachings. The effect of that witchcraft had to do with his initmate relationship with his wives, or with some of his wives, and it was reported only by ‘Aa’ishah, who mentioned that he would imagine that he had had intercourse with his wives when in fact he had not. This effect did not have any impact upon the Message; it happened by the will and decree of Allaah, for a reason. Allaah tested some of the righteous people, such as the Prophets, more severely than other people, and the test is in accordance with the degree of righteousness of a person. And Allaah knows best.