The reason is in the question they asked the Lord, they said Lord have WE or I did this or that. Not that Lord you did through me for your glory. the Gifts of the Holy Spirit are given to and operated in the person as HE sees fit for the betterment of all the body. Jesus depart from me I never knew you. that was the reason why not the gifts they were operating in. The motive as to why they did it. signs and gifts are. Also many suggest that applies to all no matter what they do. that is not the case. Seeking after an expierance is not wrong. To seek after something you have to believe you will receive it. The action after you receive is the testimony of ones motives. Seeking a gift is not wrong. Seeking a sign to believe is wrong. one who seeks a gifts has faith , those seeking a sign want confirmation to believe, AS Jesus said in John to Thomas who believed after he saw. Jesus did not say he was not saved did he?
Jesus also rebuked them for being workers of iniquity, not for doing miracles. In this passage, He had also just warned against false prophets.
Jesus was not saying it was a sin to cast out devils. He did that. He would send His apostles out with power to do that and more.
Was it wrong for Israelites to seek Jesus because He did miracles?
John 6:26
Jesus answered them and said, Verily, verily, I say unto you, Ye seek me, not because ye saw the miracles, but because ye did eat of the loaves, and were filled.
In Matthew 12, it is quite likely that the people were demanding a sign. They may have been demanding a sign to test if Jesus was a Prophet, or to see if He was THE Prophet like unto Moses based on this:
Deuteronomy 18
17 And the Lord said unto me, They have well spoken that which they have spoken.
18 I will raise them up a Prophet from among their brethren, like unto thee, and will put my words in his mouth; and he shall speak unto them all that I shall command him.
19 And it shall come to pass, that whosoever will not hearken unto my words which he shall speak in my name, I will require it of him.
20 But the prophet, which shall presume to speak a word in my name, which I have not commanded him to speak, or that shall speak in the name of other gods, even that prophet shall die.
21 And if thou say in thine heart, How shall we know the word which the Lord hath not spoken?
22 When a prophet speaketh in the name of the Lord, if the thing follow not, nor come to pass, that is the thing which the Lord hath not spoken, but the prophet hath spoken it presumptuously: thou shalt not be afraid of him.