Psalm 40 is absolutely not Messianic in any way.
Did you know that the Talmudic rabbis interpreted all kinds of obscure verses to be Messianic? They saw hints and allusions to the Messiah in hundreds of unusual biblical texts, in passages that are totally unrelated to anything Messianic. In contrast with this, Psalm 40 has some very important Messianic themes.
As we noted in the previous answer, the Talmudic rabbis applied all kinds of scriptural passages to the Messiah, many of which seem quite far-fetched. Can the same be said of the use of Psalm 40 in the Letter to the Hebrews in the New Testament? Let’s consider the evidence.
Several verses from Psalm 40 are quoted with reference to Jesus the Messiah in Hebrews 10 (see Heb. 10:1–10). The author’s point in that chapter is that “the law is only a shadow of the good things that are coming—not the realities themselves. For this reason it can never, by the same sacrifices repeated endlessly year after year, make perfect those who draw near to worship” (Heb. 10:1). He finds support for his view in Psalm 40 where the psalmist (who is David, according to tradition) states:
Sacrifice and offering you did not desire,
but my ears you have pierced;
burnt offerings and sin offerings
you did not require.
Then I said, “Here I am, I have come—
it is written about me in the scroll.”
Psalm 40:6–7
What then is the problem? For many, it is that these words are attributed to Jesus in Hebrews: “Therefore, when [Messiah] came into the world, he said: ‘Sacrifice and offering you did not desire, but a body you prepared for me;255 with burnt offerings and sin offerings you were not pleased. Then I said, ‘Here I am—it is written about me in the scroll—I have come to do your will, O God’ ” (Heb. 10:5–7). How can these statements be attributed to Jesus? And did the writer of Hebrews actually believe that Jesus spoke the words of Psalm 40? Let me explain the background and meaning of the psalm. Then you will be able to understand why Hebrews 10 quotes it in a Messianic context.
After experiencing a great deliverance, the psalmist caught a glimpse of something new (Ps. 40:3) and crucial: “God isn’t looking for sacrifices and offerings, he wants me—my total, unreserved obedience.” In other words, “God doesn’t want me endlessly offering sacrifices for my sins and disobedience. He wants me to obey!” And as the psalmist—David?—considered the words of the Torah, repeatedly calling for sacrifices to be offered up on the altar of the Lord, he said to himself, “Sacrifice and offering you did not desire, but my ears you have pierced; burnt offerings and sin offerings you did not require. Then I said, ‘Here I am, I have come—it is written about me in the scroll’ ” (vv. 6–7).256
What does he mean? There are many different interpretations given by the commentators, both Jewish and Christian, but I personally believe he was saying, “When I read about the offerings in the scroll of the Law, I came to realize that it really speaks of your desire for me—my life given wholly over to you.” Unfortunately, just a few verses later, the psalmist goes on to lament his own sins and failures: “For troubles without number surround me; my sins have overtaken me, and I cannot see. They are more than the hairs of my head, and my heart fails within me” (v. 12). What a confession! He is saying, “I see that God wants my life wholly yielded to him. That is the sacrifice he seeks. But I’m a sinner, overwhelmed by my iniquity.” He saw the lofty ideal of the Torah; he failed miserably to live it out.
Once this psalm became part of the Hebrew Bible, it took on a life of its own, as Israelite worshipers would sing and pray these words for themselves—and every one of them would fall short of the ideal, just as the psalmist did. And this continued until the one perfect Israelite came into the world, the Messiah, the only one who was completely obedient, the one who could truly say, “In the scroll of the book it is written about me,” since he was the ultimate sacrifice, the perfect offering, the one who fulfills the image of the sacrifices of atonement and cleansing. His life satisfied the real meaning of the sacrificial system. He was not just the one who was totally yielded to the will of the Father; he was the one who actually offered himself up as a sin offering (see above, 4.1).
So, according to Hebrews 10, when Jesus the Messiah came into the world (not meaning the moment he was born, but typically and prophetically), he said, “God, you don’t want more sacrifices and offerings. You have already received hundreds of thousands of lambs and goats and rams and bulls. You want me! I’m the one you spoke of in your Law”—and for the first time, the Scripture was fulfilled and the goal was realized. It makes perfect sense!
255 For discussion of the translation of this phrase (“a body you prepared for me” in the Greek as opposed to the “my ears you have pierced, dug through” in the Hebrew) in Hebrews 10:5, see 5.5.
256 For an interesting midrashic interpretation, cf. Midrash Ruth 8:8, on Ruth 4:19.
[1]Brown, M. L. (2003). Answering Jewish objections to Jesus, Volume 3: Messianic prophecy objections (129). Grand Rapids, Mich.: Baker Books.