Jeremiah or Zechariah?
Then was fulfilled what had been spoken by the prophet Jeremiah, saying, “And they took the thirty pieces of silver, the price of him on whom a price had been set by some of the sons of Israel, and they gave them for the potter’s field, as the Lord directed me” (Matt. 27:9-10).
Strangely these exact words do not appear in Jeremiah's text, and many commentators will say these words are actually found in Zechariah 11:12-13.
That's not entirely accurate though. One explanation is that Matthew was inspired to fuse different prophecies together. The words from the quotation are found in both Jeremiah and Zechariah, though neither prophet uses the particular phrasing Matthew does.
Zechariah says, "They weighed out my wages, thirty pieces of silver" (Zech. 12b) and then, "I took the thirty pieces of silver and threw them to the potter in the House of the Lord" (Zech. 11:13c).
If the cynics are right, and this is an error on Matthew's part by attributing words to Jeremiah that are in fact Zechariah, why wouldn't Matthew have cited the silver being thrown "into the House of the Lord"––which is exactly what Judas did? (Matt. 27:5)
Also Zechariah's text says nothing about the purchase of a "potter's field." Jeremiah does––he speaks of spilling "innocent blood" and the subsequent name change of the valley outside the "Potsherd Gate" (Jer. 19:4-6) as well as the purchase of that "field" later (Jer. 32:6-7).
Even though there's overlap between Jeremiah and Zechariah (contemporary prophets, by the way), Matthew seems to be summarizing Judas' and the chief priests' actions by combining their prophecies.
Since Jeremiah (in the Hebrew Bible) heads the prophetic books (and is considered a major prophet), it's possible Matthew attributed the prophecy to him, knowing he was combining the words of more than one prophet.
Jesus does something similar in Lk 24:44: "This is what I told you while I was still with you: Everything must be fulfilled that is written about me in the Law of Moses, the Prophets and the Psalms."
Notice He seems to name two groups of books and then a specific book––the Psalms. In reality, He's naming three groups of books that encompass the entire Old Testament.
"The Jews ordinarily divided the Old Testament into the law, the prophets, and the holy writings, which they called the Hagiographa" (Matthew Poole)
"The word Psalms here probably means what were comprehended under the name of "Hagiographa," or holy writings. This consisted of the Psalms, Proverbs, Job, Song of Solomon, Ruth, Lamentations, Ecclesiastes, Esther, Daniel, Ezra, and Nehemiah, and the two books of Chronicles. This division of the Old Testament was in use long before the time of Christ, and was what He referred to here; and He meant to say that in "each of" these divisions of the Old Testament there were prophecies respecting Himself" (Albert Barnes).
Matthew could've been following a similar convention or, being inspired by the Holy Spirit, had miraculous knowledge of what Jeremiah prophesied apart from what he dictated to Baruch––the scribe who recorded his book.
If cynics and unbelievers declare Matthew "blundered," the burden of proof is on them.