This problem (Matt 27:9) is an old "chestnut". Various solutions have been proposed and I will not repeat all of them. So allow me to mention a few plausible explanations for this apparent discrepancy.
Jeremiah Did Say That
It should be observed that Matthew does not quote the Hebrew nor the LXX. His quote only resembles the general idea. Therefore, it is possible that he did not quote Zechariah but did actually quote Jeremiah, but what he quotes is nothing that Jeremiah actually wrote but only something that survived in an oral tradition. (In that form, perhaps Zechariah also quoted the same source??) Since then, the oral tradition has vanished and only Jeremiah's written legacy survives. (A similar phenomenon may also exist when Jude 14, 15 quotes the prophet Enoch - only Enoch's oral tradition survived at the time of Jude's writing.) See also 1 Chron 21:19, 2 Sam 12:25, etc.
Jeremiah did Write That
It is also possible that Jeremiah left more writings than just the book that has his name and Lamentations. It is possible that one of these other writings was still extant in the time of Matthew but has now been lost. There are numerous references to other work throughout the OT that no longer exist such as the Book of Jasher (Josh 10:13, 2 Sam 1:18); Nathan the prophet (1 Chron 29:29, 2 Chron 9:29), and others.
Different Reference Method
It is also possible that in Matthew's day, each section of the OT was loosely called by the first book/prophet in that section. Certainly Zechariah is in the section that begins with Jeremiah and so to quote something from the OT in the section of Jeremiah (which includes Zechariah) may be entirely understandable. Despite the logical "neatness" I still find this unsatisfying and not entirely convincing, because I cannot find many other places where this sort of thing occurs.
There are a number of other explanations in various quarters. Here is a sample.
Did Matthew Misquote the Old Testament?