The text of Heb 10:5-7 appears to be loosely quoting Ps 40:6-8; however, it is not quite the original Hebrew but the Greek translation known as the Septuagint, LXX. Let me be specific:
Ps 40:6-8 (Hebrew, Masoretic text) - Sacrifice and offering You did
not desire, but my ears You have opened. 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: I delight to do Your will, O my
God; Your law is within my heart.”
However, in the LXX we have (where it is numbered Ps 39:7-9) -
Sacrifice and offering thou wouldest not; but a body hast thou
prepared me: whole-burnt-offering and [sacrifice] for sin thou didst
not require. Then I said, Behold, I come: in the volume of the book it
is written concerning me, I desired to do thy will, O my God, and thy
law in the midst of mine heart.
Note that neither text has "But a body hast thou prepared me". Ellicott comments on this:
But a body hast thou prepared me.—Rather, but a body didst Thou prepare for me. Few discrepancies between the LXX. and the Hebrew have
attracted more notice than that which these words present. The words
of the Psalmist are, “In sacrifice and offering Thou hast not
delighted: ears hast Thou digged for me.” As in Samuel’s words,
already referred to as containing the germ of the psalm, sacrifice is
contrasted with hearing and with hearkening to the voice of the Lord,
the meaning evidently is, Thou hast given me the power of hearing so
as to obey. A channel of communication has been opened, through which
the knowledge of God’s true will can reach the heart, and excite the
desire to obey. All ancient Greek versions except the LXX. more or
less clearly express the literal meaning. It has been supposed that
the translators of the LXX. had before them a different reading of the
Hebrew text, preferable to that which is found in our present copies.
This is very unlikely. Considering the general principles of their
translation, we may with greater probability suppose that they
designed merely to express the general meaning, avoiding a literal
rendering of a Hebrew metaphor which seemed harsh and abrupt. They
seem to have understood the Psalmist as acknowledging that God had
given him that which would produce obedience; and to this (they
thought) would correspond the preparation of a body which might be the
instrument of rendering willing service. If the present context be
carefully examined, we shall see that, though the writer does
afterwards make reference (Hebrews 10:10) to the new words here
introduced, they are in no way necessary to his argument, nor does he
lay on them any stress.
Similarly, Matthew Poole observes:
But a body hast thou prepared me: but, the Hebrew text reads, the ears hast thou bored for me. The apostle makes use here of the Greek
paraphrase, a body hast thou fitted me; as giving in proper terms the
sense of the former figurative expression, discovering thereby
Christ’s enitre willingness to become God’s servant for ever, Exodus
21:6; and that he might be so, which he could not as God the Son,
simply, the Father by his Spirit did articulate him, and formed him
joint by joint a body; that is, furnished him with a human nature, so
as that he might perform that piece of service which God required,
offering up himself a bloody sacrifice for sin, to which he was
obedient, Philippians 2:8. Thus were his ears bored, which could not
be if he had not been clothed with a body.