Good question.
Well, it would be helpful if we have a verse declaring what the Will of God is. 1 Thess 4:3 is one such: "For this is the will of God, even your sanctification, that ye should abstain from fornication:" So the Will of God is our sanctification, that we abstain from all immorality. My opinion is that those mentioned did not do this, i.e. they lived in immorality and didn't do God's Will.
So, how did they work miracles? Well, the Lord Himself never says they worked miracles, but rather they claimed to do it. Maybe like those mentioned in Acts 19, they attempted to do it, but never did it successfully: "13 Then some of the itinerant Jewish exorcists undertook to invoke the name of the Lord Jesus over those who had evil spirits, saying, “I adjure you by the Jesus whom Paul proclaims.” 14 Seven sons of a Jewish high priest named Sceva were doing this. 15 But the evil spirit answered them, “Jesus I know, and Paul I recognize, but who are you?”
Now, these seven sons of Scaeva never gave their life to the Lord, nor did His Will. They merely saw that Christians were doing mighty works in the Name of Our Lord Jesus (also kinda like Simon Magus in Acts 8:19-20), and attempted to copy them. But the Lord of course knew their heart, and so was never pleased with them.
That's my understanding. God Bless.