Psalm 38 is one of brokenness and anguish before the Lord as a result of sin. It is yet another psalm of penitence (like Psalm 6, 25, 32, 51, 102, 130 and 143). David repented of his sin, but still the sorrow of the sin remained in his memory, so this psalm is entitled "remembrance". It may also relate to one of the Levitical offerings of incense unto the Lord, wherein God's forgiveness is remembered in answer to prayer and the offering of atonement. God, however, had forgiven David, and once God forgives, the sin is not remembered but forgotten (Isaiah 43:25; 44:22).
David knew he had sinned and that a divine rebuke was necessary; so as he began to pray, he did not ask God to withhold His rebuke or chastisement, but he asked that His wrath be removed from those punishments (38:1). The believer cannot bear divine wrath, but divine chastisement, which is done in love, is beneficial and should be welcomed, for it leads us to partake more in God's holiness, and because of it we know God loves us and that we are His children (Proverbs 3:11; Hebrews 12:5-11). Once David confessed his sin and repented, the wrath of God would no longer be upon him.
The particular sins for which David repented were likely his adultery with Bathsheba and the murder of her husband, for this was the most grievous point of his life (2 Samuel 11; 12:13-14). David referred to his sin as "iniquity" (38:4, 18), which is a perversity that implies a moral failure. His unconfessed sin was like an unbearable, heavy load upon him (38:4), and it turned to mental and spiritual anguish (depression, fear, and anxiety), which then gave rise to physical infirmities. David felt as though arrows from God were piercing him (38:2). Truly the Holy Spirit was putting him under the conviction of his sin, and he was racked with guilt (38:8).
Like Job, his friends and family abandoned him as though he had a contagious disease like leprosy, and his enemies saw it as an opportune time to lash out at him. Throughout the persecution, David reacted in the same manner as did Jesus when He was accused; he remained silent (38:13-14; Matthew 27:12-14). He knew God was still watching him (38:9) and was confident that God would vindicate him and bring justice to the wicked. David did not have to defend himself; God would defend His own honour and the honour of His representative. David showed true repentance by being sincerely sorry for the sin itself, not merely for the results the sin brought. He closed his petition for mercy with a confident prayer, believing that his compassionate God would quickly bring salvation.
Psalm 39 appears to be a sequel to the previous psalm, but here David seems in even deeper despair. He feels his life will soon be over but still has hope, and therefore he is awaiting the Lord's deliverance. Psalm 38 spoke of his silence before men, but here the psalmist has resolved to be silent before God and man, lest he complain against God, as did Job. From the similarities, it appears the psalmist was familiar with the Book of Job, and he learned from Job the folly of trying to contend with God. Since the wicked people were around him, possibly tempting him to curse God, the psalmist did not want to criticize God's ways, lest they hear and he do harm to the cause of the righteous.
His bitterness within, however, was smoldering, and he had to give vent to his feelings. Finally, when he spoke to the Lord, he wanted to know how much longer he must suffer from His plague before death would overtake him. He felt wasted away and very insignificant. He also felt that compared to God, who is without age, he is but a vapour and the work he does and the wealth he heaps up during his lifetime is all in vain (39:5-6; cf. Ecclesiastes 1:18; 5:16). In the natural, he is without hope, but it is only with God that he has any hope, for without God life is truly futile.
The psalmist is repentant, for he realizes that it is only after the Lord has delivered him from all his transgressions (39:8a) that there will be real purpose to his life. With his new-found hope, he has the faith to ask and believe that God will hear him, heal him, and look upon him with lovingkindness rather than wrath, so that his strength may be renewed.