The location of the sermon on the mount is very important, because it tries to show that what Jesus is doing here is similar to what Moses has done in the Exodus experience. Consider the parallels.
1. Moses leads the people out of Egypt through the Red Sea, into the wilderness and finally to a mountain where the people receive the ten commandments.
2. The gospels have Jesus pretty much do the same thing. After Jesus' stint in Egypt, he is baptized in the Jordan river (which is similar to the crossing of the Red Sea), he goes into the wilderness and he goes up to the mountain to give the "law" as well. The law here is the sermon on the mount.
What the gospel writers are trying to suggest from a theological and literary perspective is that Jesus is the new Moses, the better Moses. Instead of giving an old law, he gives a new law that speaks of the heart.