Read the whole psalm.
It is David speaking of himself, not knowing that some of it was in regard to Christ and himself.
The following isn't about Jesus,
Ps 40:12 For innumerable evils have compassed me about: mine iniquities have taken hold upon me, so that I am not able to look up; they are more than the hairs of mine head: therefore my heart faileth me.
The writer of Hebrews speaks of Jesus in verse 5. We know this because the writer uses the word He
Heb 10:5 Wherefore when
he cometh into the world, he saith, Sacrifice and offering thou wouldest not, but a body hast thou prepared me:
Heb 10:6 In burnt offerings and [sacrifices] for sin thou hast had no pleasure.
Then the writer uses the word
I like David did. Here as David he is saying that He came to do God's will as it is written in the volume of the Book of him. That Book being the Book of the Law.
Heb 10:7 Then said
I, Lo, I come (in the volume of the book it is written of me,) to do thy will, O God.
Then the writer goes back to verse 5 in verse 8 and in doing so the writer goes back to referring to Jesus in regard to the same verse that he claimed for himself as David did. How do we know? Because the writer uses the word he again.
Heb 10:8 Above when
he said, Sacrifice and offering and burnt offerings and [offering] for sin thou wouldest not, neither hadst pleasure [therein]; which are offered by the law;
Heb 10:9 Then said he, Lo, I come to do thy will, O God. He taketh away the first, that he may establish the second.