All sorts of things are wrong for David – its physical, mental, both. He’s faint, his bones are in agony, his soul is in anguish. He is worn out from groaning, which suggests the physical may be coming from the mental. There are tears before and after bedtime, he is pulling no punches about how extremely low he is. He bargains with God to deliver him: if I am silenced by death, how will I praise you then, eh?
He connects his suffering to God’s anger and wrath, but asks God not to punish and rebuke him in his anger, like there is some extra level of bad that could come – though it may just be a poetic emphasis. His prayer is that God will “turn” and deliver him, which fits with the language in other psalms of God looking away, or hiding his face as an understanding of suffering.
The psalm is 90% about pain. Victory, such as it is, is knowing that God will hear and accept his cries for mercy. The punishment for the enemies is being overwhelmed with shame and anguish — they will “turn back” and suddenly be put to shame.
I imagine the enemies of David writing him off, leaving him behind, discounting him from their thinking because they have been able to break him. They would assume that his failure and grief would mean he gave up on God. The turning back that the enemies do I imagine being like an anticipation of gloating in his broken-ness, and being ashamed and frustrated to the point of being overwhelmed because he is clearly still more at peace with God than they are. Like those prison camp movies where the guards humiliate the prisoners but ultimately fail because they cannot break their spirit.