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:
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:
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:
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 did), 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.