The Idea in Brief
The Hebrew verb to pierce (כָּרָה = H3738) in Psalm 40:6 is the same triliteral root for the Hebrew verb to prepare (כָּרָה = H3739). For example, this second verb (כָּרָה = H3739) appears translated in 2 Ki 6:23 as "prepared." In other words, both verbs have the exact same triliteral root, but have different meanings. The LXX translators had thus understood the verb in this verse not as H3738 ("pierced"), but as H3739 ("prepared").
Additionally the LXX translators understood the word "ears" as metonymy for obedience. Thus the proper rendering in Hebrew would be that the Lord prepared the ears of David for obedience to the Lord. In contradistinction, the ears of King Saul were unprepared:
1 Sam 15:22 (NASB)
22 Samuel said, “Has the Lord as much delight in burnt offerings and sacrifices As in obeying the voice of the Lord? Behold, to obey is better than sacrifice, And to heed than the fat of rams.
In the passage of Psalm 40:6, the LXX translators did not limit the idea to the unstopping or unclogging of the ears of David, which would have been the translation of (כָּרָה = H3738), which means to pierce (or to dig into, as if unstopping of unclogging the ears). The LXX translators went farther: they understood that the Lord had prepared (כָּרָה = H3739) the ears of David in order for him to hear the voice of the Lord, and thus to obey. If and when the ears obey, then the whole person follows, and in this regard King David as a person (his whole body) was a type of living sacrifice to the Lord.
Discussion
First, many modern commentaries understand the context here to refer to the piercing of the ear and/or lobe(s), and in this regard make reference to Ex 21:6 and Deut 15:17, where the ear (singular) is pierced on the doorpost. Keil and Delitzsch (1996), however, indicate that Biblical Hebrew does not support such an interpretation. Instead, Keil and Delitzsch argue that the correct understanding of this verse has to do with the obedience enabled by the Lord, which is consistent with the contrast found 1 Sam 15:22. This verse references the disobedience of King Saul, whose ears were not "listening" -
1 Sam 15:22 (NASB)
22 Samuel said, “Has the Lord as much delight in burnt offerings and sacrifices As in obeying the voice of the Lord? Behold, to obey is better than sacrifice, And to heed than the fat of rams.
Second, The NETS (New English Translation) of the LXX for the Book of Psalms relies on the Greek edition of Alfred Rahlfs (1931), Psalmi cum Odis (Septuaginta: Vetus Testamentum Graecum Auctoritate Academiae Litterarum Gottingensis editum X), Göttingen: Vandenhoeck & Ruprecht, 1967. According to the preface of the NETS translation, the version from Rahlfs is the most reliable text of the Psalms in Greek extant. The translation in English therefore appears as follows:
Psalm 39:7(6) (NETS)
7(6) Sacrifice and offering you did not want,
but ears you fashioned for me.
Whole burnt offering and one for sin
you did not request.
NOTE: LXX Psalm 39:7(6) = Psalm 40:6 of the Masoretic Text
According to apparatus criticus of Rahlfs' Septuaginta (upon which the NETS translation was based), the following appears:

According to this citation, Rahlfs relied on the text rendering of ὠτία, which (according to the apparatus criticus) had stemmed from the Psalterium Gallicanum (as noted by the abbreviation "Ga"), which is the Latin translation of the Psalms by Jerome in the Fourth Century. That is, Jerome had relied on the Greek of the Hexapla, which Origen of Alexandria had compiled in the Third Century. In this regard, the Greek of the Hexapla predated the Codex Vaticanus (c. Fourth Cent.), Codex Sinaiticus (c. Fourth Cent.), and Codex Alexandrinus (c. Fifth Cent.), upon which the variant readings of this verse are based. In other words, Rahlfs leaned more toward the earliest appearance of this verse in Greek of the Hexapla, which reflected the reading of "ears" (ὠτία) instead of "body" (σῶμα).
However, when we look at other writings of Origen who had compiled the Hexapla (which no longer exists in its complete original), we see other nuances, which warrant more attention. That is, Origen wrote his Commentary on the Epistle of Romans, which still exists, and in this commentary he mentions the context of Psalm 40:6 in terms not of "ears," but of "body." In his commentary of Romans 12:1, which speaks of the daily sacrifice of the body in devotion to the Lord, Origen writes the following (with emphases added).
Please click the image to enlarge.

Origen mentions neither "ears" nor "body," but appears to take Psalm 40:6 in the same way that Keil and Delitzsch understand the Psalm: that is, the "ears" would be metonymy for obedience, and thus the image of the "body" as the "prepared" sacrifice.
In summary, what we may infer from this data is that the proto-Hebrew Text had indeed mentioned the "ears" (as Origen made clear in his Hexapla), however, the key verb in the verse seems to have more to do with H3739 ("prepared") than with H3738 ("pierced"), and therefore the "ears" would be metonymy for obedience, which is what the LXX translation and Christian New Testament indicate.
Conclusion
The apparent difference of translation between the LXX and the Masoretic Text of Psalm 40:6 may leave doubts as to whether or not the proto-Hebrew Text had ever mentioned "ears," since the word "body" is instead mentioned by three very reliable LXX codices (Codex Vaticanus, Codex Sinaiticus, and Codex Alexandrinus). However, one significant key to understanding this passage comes from Origen of Alexandria. That is, on the one hand, he is the earliest witness extant who indicates in his Hexapla that the proto-Hebrew texts had used the word "ears" and not "body." On the other hand, Origen interprets the meaning of the verse to say the "body" is "prepared" (as a living sacrifice), which is the meaning found in the three principal codices of the LXX and the Christian New Testament (see Heb 10:5).
In conclusion, while Origen had a reputation for interpreting Scripture in very wide brush-strokes, in this particular instance he appears to bridge the gap between the literal Hebrew Text reading ("ears"), and the amplified translation of the LXX ("body") as found in the major codices of the LXX. (As already noted this view finds support with Keil and Delitzsch.) In other words, Origen had recognized the literal text rendering of "ears" (per the Hexapla), but he also had understood the triliteral root כָּרָה meaning not to pierce (כָּרָה = H3738), but to prepare (כָּרָה = H3739). Because of this nuance of the Hebrew verb, Origen seems to indicate (like Keil and Delitzsch) that "ears" in the Hebrew Text would be metonymy for obedience, which therefore appears as "body" in the three principal codices of the LXX and in the Christian New Testament as well.