It’s not a transcript.
first appears by the unknown author of Matthew 80 - 90 years after the words were spoken.
That’s debatable. Some put the composition of Matthew much earlier (and written by Matthew—who was there).
The Gospels do not record history the way that we write history in the U.S. today. It’s not necessarily an official transcript of the exact words Jesus used.
A few observations, though. Jesus went around preaching and teaching for three years. I have known people who do a lot of teaching/public speaking. They repeat themselves. They use stories. And people remember them. I can think of a few occasions where I have seen the same person give the same talk so many times that I can basically give it myself.
It’s not difficult for me to imagine that Jesus would have repeated certain teachings and parables to different audiences. And the apostles who were with him would have heard these stories multiple times. Now, setting aside arguments about the date and authorship of the Gospels, whether it was written by Matthew in 50 or 60 AD or written by a disciple of Matthew in 80 or 90 AD, even that disciple would have heard Matthew speak on these things many times and would have similarly committed these things to memory.
Keep in mind, too, that the people of this time did not have all the distractions or the excuses to be lazy (ahem…Google…ahem). So they would have been much more apt to remember the words of Jesus. Even more so when he use stories, or when he structured his teaching in ways such as with the Beatitudes.
Add the Holy Spirit to the mix who inspired the sacred authors, and it doesn’t seem far-fetched at all that Jesus’ words would be accurately recorded in the Gospels. Whether or not it is a word-for-word transcription of a singular sermon is a moot point.