Actually, this problem, like many created by Matthew's expansion of the 'Sermon on the Plain' in Luke, is best frankly faced and explained by recognizing that much of the content in Matthew's 'opus' version of the speech, is inspired by at least three important motives or goals:
(1) Matthew blends the Lukan version with the Letter of James, in an attempt to create an inclusive syncretistic version acceptable to both followers of Paul (Gentile Christians) and followers of James (Hebrew Christians). The result, while achieving a certain unity does so at a cost.
a) The plain but inconvenient social gospel in Luke is removed entirely, so as not to embarrass the middle-class converts swelling the ranks of Christianity at the time of its early expansion.
b) Jesus comes off strongly in favour of Old Testament Law, a position taken by Jewish Christians but antithetic to the Spirit of Paul's work.
(2) Matthew gathers various sayings of Jesus sprinkled throughout Luke and gathers them into a single large topical sermon. In fact, Matthew creates Five large sermons out of Jesus' sayings, to mimic the Five books of Moses and present Jesus as the New 'Moses'. Unfortunately, those original contexts are often lost, and Jesus comes off rather stern and harsh, compared to His more natural and realistic portrayal in Luke, Mark and John.
(3) Matthew wants to create a 'Gospel' that can be publicly read in worship services without incurring the wrath of the Roman authorities, or suspicion and criticism of the Jews who actively oppose Christianity. To do this Matthew:
a) removes references to the Roman Occupation, like the name of the 'demon' LEGION (Luke 8:26f/Matt.8:27f) and inserts 'anecdotes' about Jesus actually paying taxes (Matt.16:24).
b) engages in polemics and applogetics against Jewish criticisms, and adds comparisons to Jewish practice, as well as toning down nasty 'parable-stories' like the cursing of the 'Fig Tree' (the symbol of the Southern Kingdom of Judah).
When you add up all these editing procedures, the dramatically different tone and content of Matthew is easily accounted for.
The question of 'prayer in secret', like cautions against 'taking oaths', are best understood as polemics against Jewish practice and criticism of the Jews who were kicked out the synagogues because they were converts to Christianity. As original teachings of Christ they are likely secondarily derived from original sayings and teachings of Jesus in other contexts.