What do these verses mean in the context?
You might be wondering what exactly these verses meant to the people of the day when Jesus was speaking. Good, cause I’m gonna explain that!
First of all, I should explain that the Sermon on the Mount was simply the way in which Jesus decided to present the idea of true righteousness, and how to live in such a way, to this followers. This particular section is when Jesus provides his disciples with an easy to understand explanation of how they should give to the needy.
During this time period, it was very normal for the Jews to give alms (which could be money or food) to the poor. The government provided the needy with little or no assistance, leaving them to the people to take care of. Apparently, many people who took part in this alms-giving would do it in very public settings where they could be admired by others for their good deeds. So basically, a lot of people would only give so that they could get positive attention from others.
What Jesus is really trying to get across here is the problem of motive. Jesus is calling out the fact that most people give with their own selfish motivations in mind- namely being positively recognized by others. The most obvious example of people who did this were Pharisees. In the parable of the two men who prayed (Luke 18:9-14), a Pharisee is depicted boasting in the streets about how awesome he is compared to others and how much money he gives. That message is paralleled in this passage. Doing good things just so you can brag about it and appear to be righteous is not true righteousness. This attitude is clearly not popular with Jesus. He will know if you have the right motivation in your heart.
Jesus is encouraging his listeners to give because that is the right thing to do. Not for one’s own glory, but for the glory of the Lord. He even says to give in secret, so that no one can praise you but God.