The psalm laments the fact in vv.1-3 that, since their youth, Israel has been persecuted by the nations. Yet, as v.4 makes plain, they have not been abandoned:
But the LORD is righteous;
he has cut me free from the cords of the wicked.
Notice that it is YHWH who is declared to be righteous and that in the context of rescuing his people, Israel. Whilst the term 'covenant' fails to put in an appearance here, the whole context is so clearly covenantal. And YHWH's righteousness is seen in his acting to rescue his people as the outworking of that covenant.
Is he also being ethically righteous in rescuing the oppressed? Without doubt; but the emphasis, in terms of salvation-history, is on covenant faithfulness. Righteous is what righteous does - and YHWH in righeousness delivers his own, for the sake of the world.