Shaykhul Islam ibn Taymiyah wrote in "Furqan Bayna Awliya Rahman wa Awliya Shaytan" Eng tran p 155:
"It is not a prequisite for a Waliy of Allah that he be free of sin or error, instead it is possible that some knowledge of the Shariah be unknown to him or some aspects of the religion confuse him to the extent that he think that some matters commanded by Allah are actually prohibited by Him. It is possible that he think that some occurences are from the miracles of the Awliya of Allah, the Exalted, while in reality they are from Shaytan who has disguised them and (hence succeeded in fooling him) so that he is unaware that they are from him due to his lesser ranking. None of this ejects a person from being included amongst the ranks of the Awliya of Allah, the Exalted. This is because Allah, the Glorious and Exalted, has overlooked this nation's genuine errors, acts of forgetfulness and those things they were coerced into doing"
Shaykh Salih Aal Shaykh wrote in explanation of it, p 160, Maktabah Dar Al-Hijaz:
"This distinction is a fundamental in the topic of Wilayah, and it is that it is not a condition for the Wali not to err at all or that he never errs, or that he doesnt have confusion in some important matters in Aqidah or Shariah, or that he does not have a deficiency in acting in some matters, and it is not a condition for the Wali that he becomes complete…"
On p 236, Sh Salih explain 2 kinds of Karamat and how rarely they can occur for people who have mistakes and innovations:
"First category: Karamah Ilmiyah
Second: Karamah from direction of power and influence.
As for Ilm, it can be "Ilmiyan Kashfiyan", by knowing things hidden, like Abu Bakr knew about sex of newborn, he saw what was in the womb of the woman, so As-Siddiq said: "A girl is shown to me"
It can be "Ilmi" with listening, so he hears what other do not hear, like Saariyah when he heard the speech of Omar, or hearing things that habitude does not make listen with long distance, as the Karamah that occured for Omar…
As for the second, it is from perspective of Qudrah (power) and influence, meaning that he is capable of doing thins other cannot do, or he can have an influence in the creation others cannot have. When we say he has influence or he is capable, IT IS ALLAH MAKING THIS OCCUR ON HIS HAND (IJRA ullahi ala yadayhi zalika), as we have defined Karamah with our saying: "What Allah makes occuring from Khawariq Adaat (things above natural habitude/breaking natural laws) upon the hand of the Wali, and the MEANING IS NOT THAT HE GIVES HIM POWER AND INFLUENCE as stipulated by extreme Sufis until they reached level; of saying for the one they believe to be Wali that he says about something "Be" and it is. IT IS ONLY ALLAH MAKING THESE OCCUR UPON HIS HAND AS AN HONOUR. IT DOES NOT MEAN THAT HE HAD A PERPETUAL POWER OF INFLUENCE OR TRANSFORM THINGS OR SIMILAR THINGS…
When this has become clear, the Karamah can occur upon the hand of other than a Wali. The basis is that it occurs only to the obedient, the pious Wali, the fearful believer. It can occur for the disobedient and it CAN OCCUR FOR THE INNOVATOR. This happens rarely, it is only to strenghten his faith because of its weakness or because he is defending the Deen so he is given honour because of his defence of the religion in opposition to the Mushrik or Kafir.
Hence it became difficult for some that a group attributes Karamat or Khawariq to the innovator, as what is mentioned in the occurence of Karamat in Afghanistan to some people who fought infidels (Tr: Russians in 80), and a group came saying: this is not correct as some of them are innovators, they have some forms of Shirkiyat, so they would deny the other group, and the other group would reply: We saw with our eyes, so they are declared truthful, so confusion spread whether they are lying or truthful.
The rule of Ahlus Sunnah in this chapter is that these were fighting infidels, and they were fighting disbelievers ennemies of Allah, and these were Muslims who were attributing themselves to the foundation of Islam, so they could be given something from the Khawariq, not for them, but for the prevalence of the religion that was with them against their ennemies, and this happens in the domain of debates, a Mutazili can debate a Christian so he is honoured with some forms of evidences that come to his mind, and this because of the foundation of the religion that is with him in opposition to the Christian Mushrik, and he can be an Ashari debating for instance and likewise, so a Karamah that occurs for a servant, it is proper to observe in it and ponder over it, and one should not rush to approve or deny"