How does Judas throwing away the 30 pieces of silver connect to the prophecy in Jeremiah?
In the case of the story of Judas' death and the pieces of silver, Matthew is referencing from Jeremiah 19. In Matthew 27, we read:
Matt. 27:7 And they conferred together and with the money bought the Potter’s Field as a burial place for strangers.
Matt. 27:8 For this reason that field has been called the Field of Blood to this day.
Matt. 27:9 Then that which was spoken through Jeremiah the prophet was fulfilled: “AND THEY TOOK THE THIRTY PIECES OF SILVER, THE PRICE OF THE ONE WHOSE PRICE HAD BEEN SET by the sons of Israel;
Matt. 27:10 AND THEY GAVE THEM FOR THE POTTER’S FIELD, AS THE LORD DIRECTED ME.”
In order to understand how Jeremiah's prohecy connexts to Matthew is difficult to explain without a full study of Jeremiah 19 (as well as significant background on Tribulation), but we can offer a brief explanation.
In Jeremiah 19 the Lord promises Israel that a day of judgment is coming as a result of the nation's sins under the Old Covenant, particularly Israel's involvement in child sacrifice in the Valley of Hinnon (south of Jerusalem). Jeremiah 19 is a prophecy set in that location, which is also the location of Judas' death. Jeremiah tells Israel that a day is coming when the nation will be slain by an adversary and the bodies will lie unburied in the Valley of Hinnon:
Jer. 19:6 therefore, behold, days are coming,” declares the LORD, “when this place will no longer be called Topheth or the valley of Ben-hinnom, but rather the valley of Slaughter.
Jer. 19:7 “I will make void the counsel of Judah and Jerusalem in this place, and I will cause them to fall by the sword before their enemies and by the hand of those who seek their life; and I will give over their carcasses as food for the birds of the sky and the beasts of the earth.
Jer. 19:8 “I will also make this city a desolation and an object of hissing; everyone who passes by it will be astonished and hiss because of all its disasters.
These curses will be fulfilled during the time of the seven-year Tribulation on earth, during which time Jews will be hunted by the Antichrist and their bodies will lay unburied in the Valley of Hinnon (like Judas' did) until the Second Coming of Christ, after which the nation of Israel will be saved and brought into the Kingdom.
So Matthew is connecting this prophecy to Judas' death because, in fact, one becomes the means to the fulfillment of the other. Because the religious leaders of Israel entice Judas to betray Jesus, the nation will be judged in a future day for rejecting their Messiah. That judgment will include the penalty of Jeremiah 19, which ironically promises that Israel will experience a fate similar to the one experienced by Jesus' betrayer.
So Matthew says Judas' death is the fulfillment of Jeremiah 19, because Judas' fate will be the fate for many in the nation of Israel in a future day because they rejected their Messiah in His day. Since one event directly leads to the other, it can be said that one fulfills the other.
To make matters more confusing, Matthew chose to reference Jeremiah 19 using words taken from Zechariah 11:13:
Zech. 11:10 I took my staff Favor and cut it in pieces, to break my covenant which I had made with all the peoples.
Zech. 11:11 So it was broken on that day, and thus the afflicted of the flock who were watching me realized that it was the word of the LORD.
Zech. 11:12 I said to them, “If it is good in your sight, give me my wages; but if not, never mind!” So they weighed out thirty shekels of silver as my wages.
Zech. 11:13 Then the LORD said to me, “Throw it to the potter, that magnificent price at which I was valued by them.” So I took the thirty shekels of silver and threw them to the potter in the house of the LORD.
Matthew wasn't quoting the prophecy of Zechariah 11, since that prophecy does not relate to the events of Judas' death. Apparently, Matthew borrowed wording from Zechariah 11 to demonstrate that Judas was a prophetic figure in God's plan for the life of Jesus (i.e., Judas didn't kill Jesus, the Father allowed the Romans to), while at the same time calling it a fulfillment of "Jeremiah" to make clear that Judas' end pictured a future fulfillment of Jeremiah 19. Matthew was more interested in showing his readers the prophetic significance of Judas' death as it related to the future consequences for Israel having rejecting their Messiah rather than merely noting the consequences for Judas personally.
While this approach to interpreting Old Testament quotations may seem convoluted and confusing, it's common to Matthew's Gospel and the rabbinical practices of Jesus' day.