Isn't it an extraordinary thing that the sheep whose charitable actions are commended by the king in the judgment scene of Matthew 25:31-46 are unaware of Jesus as a beneficiary of their actions? They ask: "When did we see you hungry and feed you, or thirsty and give you something to drink?" I am accordingly cautious about interpretations that see this passage solely as an injunction to works righteousness or doing acts of righteousness.
Those on the left, or the sheep, undertake works righteousness of course but not with an emphasis on righteousness. What renders their actions worthy of inheriting the Kingdom of the heavens prepared for them before the foundation of the world is that they are actions of mercy (feeding the hungry; tending to the sick, clothing the naked, visiting the imprisoned) taken in relation to the child of the king they neither knew or identified. They were behaving simply as compassionate or not compassionate (in the case of the goats) to other human beings.
This theme of compassionate action towards others without knowing Jesus as recipient or object of actions is anticipated in the Sermon on the Mount wherein Jesus counsels against ostentatious acts of mercy:-
When you give alms (acts of charity), do not let your left hand know what your right hand is doing so that your alms maybe in secret and your Father who sees in secret will reward you (Matthew 6:1-4).