You do realize, don't you, that you are mixing up your passages. The verses that speak about those who would tell Jesus, "Lord, Lord, did we not prophesy in your name and in your name drive out demons and in your name perform many miracles?" are found in Matthew 7:22-23. Jesus answers these self-satisfied "religious" people, "Then I will tell them plainly, I never knew you. Away from me, you evildoers!". Those are obviously the ones that thought their works would save them, HARDLY nothing.
But the verses in Matthew 25:30-50, speak of the sheep and goats. Try to keep things straight, okay?
Actually, Jesus never said that those labeled goats did nothing. They could have been as religious as all get out.
Matter of fact, a lot of people will appeal to good works and Jesus will say He didn’t know them.