Carful..
The pharisees also accused Jesus of casting out demons using the power of Satan, and Jesus told them doing so they had committed the unforgivable sin.
Mat 12:
22 Then they brought him a demon-possessed man who was blind and mute, and Jesus healed him, so that he could both talk and see. 23 All the people were astonished and said, “Could this be the Son of David?”
24 But when the Pharisees heard this, they said, “It is only by Beelzebul, the prince of demons, that this fellow drives out demons.”
25 Jesus knew their thoughts and said to them, “Every kingdom divided against itself will be ruined, and every city or household divided against itself will not stand. 26 If Satan drives out Satan, he is divided against himself. How then can his kingdom stand? 27 And if I drive out demons by Beelzebul, by whom do your people drive them out? So then, they will be your judges. 28 But if it is by the Spirit of God that I drive out demons, then the kingdom of God has come upon you.
Here in mat 7. Jesus did not say their works where illegitimate, only that they where not in the will of the Father in what they had done..
In Luke 11 Jesus sums up the will of the Father by Saying we must Love God with all of our ability to do so, and to love our neighbor as ourselves. Meaning the sin these men committed was they broke the two greatest commands. So they may have legitly had the faith they needed to allow the Holy Spirit to work in them (Like Judas) But did not Love God or their fellow man as they should have.