This is one of seven Penitential Psalms, and we do not know the context. We can sense that whatever the occasion, it seems not to have struck David’s awareness all at once. Rather, the pressure of conviction grew slowly. The cultural context is that there is no set period, nor any particular course of penitence required. Rather, David must wait out the sense of personal insult he caused his Lord. By no means is there anything resembling an objective standard for such things, as if fairness would even be an appropriate concept. God forgives sin, but David’s sense of discomfort is the issue. Violating God’s moral character plays out in this world with very real consequences.
However, there is no need to take every line literally. We aren’t supposed to get lost in analyzing the precise meaning of the words beyond an expression of tendencies and David’s subjective experience. Some of this is standard Hebrew hyperbole, a sense of dramatic storytelling that was so common in his day we should be surprised when it is absent. Pay attention to David’s grasp of justice, that he never disputes the rightness of the punishment he feels. Rather, he pleads for mercy because there is no higher court of appeal.
Thus, David isn’t whining, but genuinely worried he could die before God can respond with a restoration of communion with David. Dying itself may well be justified, but he seeks that note of merciful acknowledgment first. So David depicts himself as one who has been grievously wounded, and the wounds are as yet untreated. Then he talks about the sense of humiliation and depression. And who wants to be around someone in that state? His friends and family keep their distance.
Instead, his enemies draw near, sensing the moment when he will be defenseless. He has no moral standing to defend himself against false accusations. While David hints that this would be a nasty way to end his life, he is confident in God’s mercy. He is not hiding anything; he confesses his guilt openly. He ends with a call on the Lord to rescue Him before it’s too late.
Addendum: It is important to understand here that this is not false guilt. At the same time, the focus is not a matter of objective legal transgression, but that David is struggling with an overwhelming sense of conviction and guilt. While the problem is internal, it is a very real moral discernment based on something far bigger and more substantial than mere feelings. David knows there is a barrier between him and God because he is morally powerless and disconnected from the Spirit Realm. His heart tells him that he is not in tune with ultimate reality. God alone can heal this inner wound.