Note that Jesus went up on the mountain to teach the Apostles *
Seeing the crowds, he went up on the mountain, and when he sat down his disciples came to him.
Later He came down with them and addressed the crowds
And he came down with them and stood on a level place, with a great crowd of his disciples and a great multitude of people from all Judea and Jerusalem and the seacoast of Tyre and Sidon, who came to hear him and to be healed of their diseases;
Luke 6:17 giving them a summary of what He had been teaching the Apostles.
Matthew was one of the Apostles; so got the version given on the mountain. Luke is reporting the statements of various eyewitnesses, who were presumably with the crowd on the plain.