Your basis? Why is one from Godly power while the other is not? And if Matthew 7 is 'ungodly', then where does that power come from? You can't redefine it after the fact to fit into your belief system. You have to accept it as is. And it is clear that those people in Matthew 7 were doing the exact same thing as those in Luke 9. Both were casting out demons in Jesus name, based solely upon the authority and power that came through Jesus. Never mind the state of salvation for those in Matthew 7. Their state has nothing at all to do with the source of their power.
What Jesus was trying to say here is that it does oneself no good in the long run to believe in the Power of Christ if one does not bother knowing Christ. From the beginning, it has always been about relationship. God is looking for a family. He gives freely to those who ask, but in the end, He is still looking for a family. Those in Matthew 7 asked for and were given the power of Christ. They even recognized Jesus as Lord, but they never put forth the effort to get to know Him.