OTOH, authors compiling a teacher's sayings into a "sermon" is a time-honoured tradition. Plato almost certainly did it with Socrates at times and it seems to be the case with some of the collections we have of Confucious and The Buddha. So, yes, he was quite capable of preaching a sermon, but whether he preached this exact, specific sermon or whether it's a compilation of his sermons and sayings, is indeterminate. I am quite certain he preached more than one sermon given that his ministry lasted something like three years by most reckoning. It unlikely they were all the same (he was extemporizing, after all, rather than reading a script) so perhaps Matthew assembled a generic "Jesus sermon" from the all the best bits of the ones he preached over the years. All we can say is that the sermon and its contents are attributed to him.