TRADITION VS SCHOLARSHIP
The answer
Both Matthew and Luke. Matthew closes the Sermon on the Mount "when Jesus had finished saying these words" (Matthew 7:28), and then "When he entered Capernaum, a centurion came to him" (Matthew 8:5). Luke closes his sermon when Jesus "had finished all his sayings," and he "entered Capernaum," where a centurion's slave lies ill (Luke 7:1-2).
Why it’s interesting
Scholars who think Matthew and Luke both drew on a lost sayings book, called Q, count this story as part of it. Those who say Luke used Matthew point to the order: a book made mostly of sayings, they argue, would not carry a sermon's ending and the move into town.
Genuinely debated
Learn the Bible.
Not just the stories, but the history, authorship, and scholarship behind it.