Then when he says, to no man rendering evil for evil, he teaches what pertains to beneficence by excluding its contrary: first, he teaches not to do evil to another for revenge; second, he teaches not to do evil for the sake of defense, at revenge not yourselves.
In regard to the first he does three things: first, he forbids revenge when he says: to no man rendering evil for evil: if I have returned evil for evil (Ps 7:5); do not repay evil with evil (1 Pet 3:9).
But this must be understood in a formal sense, as was said above of evil. For we are forbidden to return evil for evil when it is ...inspired by hatred or envy, so that we take pleasure in another's evil. But if in return for the evil of guilt which someone commits, a judge pronounces an evil of punishment in a just way to compensate for malice, he does, indeed, return evil materially, but formally and in itself he returns a good. Hence, when a judge hangs a criminal for murder, he does not return evil for evil but good for evil. This is the way the Apostle handed over to Satan the man guilty of incest, for the destruction of the flesh, that his spirit may be saved (1 Cor 5:5).
Second, he shows that even good things must be provided for our neighbor, saying: providing, i.e., you should be, good things, not only in the sight of God, so that you take care to satisfy your consciences before God, but also in the sight of all men, so that you do things pleasing to men: give no offense to Jews or to Greeks, or to the church of God, just as I try to please all men in everything I do (1 Cor 11:32). Providing good things not only before God, but also before men (2 Cor 8:21).
But this can be done properly and improperly. For if it is done for human approval, it is not proper conduct: beware of practicing your piety before men in order to be seen by them (Matt 6:1). But it is proper, when it is done for the glory of God: let your light so shine before men, that they may see your good works and give glory to your Father who is in heaven (Matt 5:16).
Source: Commentary on Romans