What they have done is taken care of “the least of these” is very simple practical ways, usually described as social responsibilities, things that were valued by the Jews at the time of Jesus. The idea that a righteous person takes care of the poor and needy is found throughout the Hebrew Bible and rabbinic thought and becomes cornerstone to Christian ethics.
Job defends himself by arguing that he has not defrauded the poor (Job 31:16-21). These same sorts of “good deeds” are typical of righteous Jews in the Second Temple Period. For example, Tobit 4:16-17: “Give some of your food to the hungry, and some of your clothing to the naked. Give all your surplus as alms, and do not let your eye begrudge your giving of alms. Place your bread on the grave of the righteous, but give none to sinners.” Likewise, Sirach 7:35 says “Do not hesitate to visit the sick, because for such deeds you will be loved. Feeding the hungry and giving drink to the thirsty are things which the person of God does because they are God’s people (Prov 25:21, Ezek 18:7-9).
The sheep are also praised for sheltering the foreigner and stranger as well as clothing the naked. This pair deals with basic hospitality requirements in the Ancient Near East. The word for stranger may mean someone from your country that is passing through your village or someone from another country. Think of this as “when I was an immigrant, refugee, etc. in your land, you sheltered me.” In b.Shab we read “Hospitality to the wayfarer is greater than welcoming the presence of the Shekinah.” Job claims that “no stranger had to spend the night in the street, for my door was always open to the traveler” (Job 31:32)
They also visit the sick and the prisoner. Visiting the sick becomes a key virtue in the early Church (see James 5:14, for example). Visiting the prisoner was necessary since the Greco-Roman prison system did not provide any food, water, or other needs for prisoners. If the person was to survive in prison, there had to be friends on the outside to bring the person food and water.
The Testament of Joseph 1:5–6 “I was sold into slavery, and the Lord of all made me free; I was taken into captivity, and His strong hand succoured me. I was beset with hunger, and the Lord Himself nourished me. I was alone, and God comforted me; I was sick, and the Lord visited me; I was in prison, and my God showed favor to me.
Babylonian Talmud (t. Bab. Nedarim) “he that does not visit the sick, is as if he shed blood: says another, he that visits the sick is the cause of his living; and he that does not visit the sick, is the cause of his death: and, says a third, whoever visits the sick shall be preserved from the damnation of hell.” Visiting of the sick was reckoned, by the Jews, a very worthy action: they speak great things of it, and as what will be highly rewarded hereafter.”
There is a question of application here – usually this verse is used to guilt people into giving to a food drive or money to a homeless shelter. While that application is fine (I am a big fan of helping the poor), but I am not so sure that is what Jesus is talking about. The people who enter “eternal life” are those who have actually done the will of God by caring for the least of the brothers. In every other text in the gospel of Matthew, the brothers of Jesus are the disciples, the Jews who are following Jesus. It is possible that Jesus is not referring to the generic poor of all ages, but specifically the disciples who will suffer greatly for their testimony.