Only the Holy Spirit anoints offices in the church with miraculous gifts. It is best to think of 'gifts' as temporary and associated with a calling to an office and sanctification as permanent calling to salvation'. Even those sanctified by faith may not be given unusual gifts unless called to an external office requiring those externally anointed abilities.
The problem with Judas is that he temporarily was assigned the former but did not partake in the latter. Judas was not 'saved through the sanctifying work of the Spirit and through belief in the truth.' (2 Thess 2:13)Jesus seems to clearly mark him out of sanctification while including him in a temporary called office here:Then Jesus replied, “Have I not chosen you, the Twelve? Yet one of you is a devil!” (John 6:70, NIV)
This does by no means indicate that God often calls people without sanctification to an office in the church with gifts. Rather it is the rare exception where he infrequently calls sinners to an office and gives them gifts, temporarily using them in order to declare his message according to his sovereign pleasure. He does not call and use them while saying a different message, for he will not manifest miraculous support of those who declare the opposite of his purpose and will in choosing them. He used Saul, Balaam and Judas in this way. He is not the author of confusion. That is why while in the office and anointed with special gifts to perform it, Judas could say on behalf of Christ, 'If you do not believe Jesus by my words about him believe the works he is doing through me under his office'.
But if I do them, even though you do not believe me, believe the works, that you may know and understand that the Father is in me, and I in the Father.” (John 10:38, NIV)
John Owen makes this distinction between sanctification of the Holy Spirit and an office anointed by the same Holy Spirit clear:
The end of God in election is the sonship and salvation of the elect, “to the praise of the glory of his grace,” Eph. 1:5, 6; and this cannot be unless his image be renewed in them in holiness or saving graces. These, therefore, he works in them, in pursuit of his eternal purpose therein. But gifts, on the other hand, which are no more but so, and where they are solitary or alone, are only the effects of a temporary election. Thus God chooseth some men unto some office in the church, or unto some work in the world. As this includeth a preferring them before or above others, or the using them when others are not used, we call it election; and in itself it is their fitting for and separation unto their office or work. And this temporary election is the cause and rule of the dispensation of gifts. So he chose Saul to be king over his people, and gave him thereon “another heart,” or gifts fitting him for rule and government. So our Lord Jesus Christ chose and called at the first twelve to be his apostles, and gave unto them all alike miraculous gifts. His temporary choice of them was the ground of his communication of gifts unto them. By virtue hereof no saving graces were communicated unto them, for one of them never arrived unto a participation of them. (The Works of John Owen, Vol 4, P430)
Judas could only work miracles and cast out demons by being directly chosen by Christ to an office that the Holy Spirit anointed with gifts to do so. God in scripture rarely does this strange thing (using his enemies to represent him) but only in an orderly way according to his divine purpose. God is not an author of confusion. Miraculous gifts are proof that God has sent and approved the message of his messengers even when temporarily are rarely overwhelming his enemies to be his mouthpieces.