The author of Hebrews (10) quotes Psalm 40:6-8 and applies it to Jesus. Yet all of the psalm cannot refer to Jesus (for example, verse 12 contains a personal confession of sin, and Jesus had no sin to confess). So it is best to read the psalm by recognising that some verses apply to Jesus but the psalm as a whole applies to David. Interpreting it in this manner allows verse 12 to be a confession of sin by David and the call for divine intervention in verses 14 and 15 to be a prayer of a godly ruler who desires the progress of God’s kingdom in Israel. His prayer also requests the prosperity of the righteous: ‘But may all who seek you rejoice and be glad in you; may those who love your salvation say continually, “Great is the Lord!” (v. 16).
How could the psalm as a whole apply to David? To help us understand how it can, we can consider its three divisions: verses 1-4, 5-10, 11-17. Verses 1-4, the first division, reveal that the psalmist had in the past experienced a dark and difficult time in which he had to exercise a great deal of patient prayer as he waited for the Lord to deliver him. David likens that ordeal to imprisonment in a pit floored by miry clay.
Yet David had been delivered in a wonderful manner, and this deliverance is described in the second section (vv. 5-10). The consequence of his deliverance was that he was given a prominent position as a teacher of the people of God. When was it that David could teach the people about the law of God? The answer is that this was one of the functions of the king (Deut. 17:18-20). David was unlike Saul who had imagined that sacrifice was more important than obedience (1 Sam. 15). Instead David delighted personally in the law of God and also sought to have his subjects obey it. So these verses are concerned with his role as king over God’s people, Israel.
The third section (verses 11-17) indicates that David has entered into another difficult period, and from this current situation of trouble he looks back to his previous deliverance. It was also a period in which many of the true people of God were disturbed, which indicates that the trouble was more than a personal crisis for David, such as what occurred after his sin with Bathsheba. Of course, David gives to us a most important insight to use when we are facing a difficult situation – in such a time of trouble we are to recall previous occasions of spiritual danger and comfort ourselves with knowing that the God who delivered us previously can deliver us again.
A possible outline for the psalm is this: (a) verses 1-4 relate to David’s time before he became king and when he was on the run from Saul; (b) verses 5-10 concern his rule as king and particularly his role in upholding the law of God; (c) verses 11-17 describe his feelings and prayers during the rebellion led by his son Absalom.