Verses 28–31 then look back to Numbers 25:1–10. There, Israel
participated in the worship of other gods. Mention here of the sacrifices of
the dead is not entirely clear even if those sacrifices are in view. Such
worship could be sacrifices offered to the dead or sacrifices that demanded the
death of people (cf. v. 37), but perhaps it is better to think here of them as
sacrifices offered to gods who are themselves dead (cf. niv; Kraus 1989: 320).
These sacrifices have no positive value, but turn people from worshipping
Yahweh. Whichever is intended, the result there was plague that was only
stopped through Phinehas’s intervention, an intervention here counted to him as
enduring righteousness, aligning him with Abraham (Gen. 15:6). (David
G. Firth, Psalms [Apollos Old Testament Commentary 14; London: Apollos,
2025], 578-79)