Jesus does not tell us what we need to do, but what we will do. Notice the motivation of the sheep, Lord, when did we see you... The sheep were not trying to earn a reward with their action.
Without faith, nothing that we do is pleasing to God. When we are saved by grace, through faith, we do good works. The sheep didn't do the good works to earn heaven, but because it was a natural fruit of their faith.
Notice verse 34: Come, you who are blessed by my Father, inherit the kingdom prepared for you from the foundation of the world.
The sheep are blessed. Verse 34 does not say, "Come, you who earned the reward."
It's not that the goats didn't do good works, it's that the goats couldn't do good works without faith.
Good explanation.