Many consider Psalm 9 and 10 to be one Psalm, or at least a two parter. Both, at least, have similar themes and verbiage, and perhaps a loose acrostic structure. However, the focus in 9 is thanking God for righteous judgement, whereas 10 is a prayer against wicked rulers.
So onto Psalm 9. It sort of picks up where 7 left off. Once again, God is the judge of the world who will vindicate his people by punishing evil. And we see here how David speaks of past judgements made to show the basis of his trust for future judgements. As opposed to many of David’s psalms, this one focuses more on Israel’s national enemies, it seems, than David’s personal ones. And any attempt to drive Israel from their land was an attack on God’s plan, and therefore an attack against God. This Psalm reminds me of the end of Moses’ song in Deuteronomy 32:40-43, or Romans 12:19 and Revelation 19:2. Revenge or repayment from a just and fair God is not evil. In fact, it reflects his holiness because he can’t leave sin unpunished.