Logically, there are two possibilities: either Jesus himself said such things or they were added to the tradition at a later date. Neither view offers a clear-cut explanation, so a wide variety of ideas for the "secretive" passages have been offered by Christian commentators and Bible scholars over the years.
Jesus did not tell anyone to remain quiet
In 1901, William Wrede was the first modern scholar to tackle the question. He decided the words, couldn't have come from Jesus because it was unreasonable to expect people to keep quiet and thus a historical Jesus couldn't have made the command. Observing that the secrecy theme occurs primarily in Mark, he hypothesized that the passages were written to explain why Jesus had not been recognized as the Messiah during his life. (The lead to explain this was based on the supposition that the earliest belief in Jesus' Messiahship began after his death.)1
Although Wrede's paper was a landmark in Biblical scholarship (the translated name of the paper gives us the "Messianic secret" name by which the passage are still described in scholarship), the ideas were attacked pretty much from their proposal.1 The idea gained currency in the 1920s, but has steadily fallen out of favor among Biblical scholars since then. By the 1970s, the theory was essentially dead, as it raised many more problems than it solved. In the words of G. E. Ladd, it "is a clever theory, but utterly lacking in evidence."2
Other historical explanations
Since Wrede, a number of other redactional explanations have been offered. In the view of Ulrich Lutz, Mark is using the motif to redefine what the Messiah is, by tying it to the cross & resurrection instead of the life of Jesus. Eugene Boring proposed that the motif grew out of an attempt to combine views that emphasized Jesus' power with views that emphasized his suffering and death.1
Others have suggested it is some sort of literary device, perhaps to let readers understand that God's revelation is a secret reserved for the elect, or to explain why many Jews rejected Jesus and the Gospel message was then spread to Gentiles instead.1
Jesus did sometimes tell people to remain quiet
Among those who see the words as coming from Jesus, a popular explanation is that public disclosure would hinder Jesus' mission. Large crowds, for example, would inhibit his ability to move about from town to town. Too much attention would attract the attention of authority figures - Jewish and/or Roman - and cause a confrontation before the time was right.1
Mold the 12
A related idea is the Jesus wanted to mold the 12 primarily through his teaching, allowing them to gradually come to accept him as Messiah. His primary mission was not to teach the public, but rather to teach the future leaders of the new Church.
The Tyndale Concise Bible Commentary takes this view, saying that Matt 12:18-21, which quotes Isaiah 42:14, is perhaps "the best explanation of Jesus' secrecy:
Behold, my servant whom I have chosen,
my beloved with whom my soul is well pleased.
I will put my Spirit upon him,
and he will proclaim justice to the Gentiles.
He will not quarrel or cry aloud,
nor will anyone hear his voice in the streets;
a bruised reed he will not break,
and a smoldering wick he will not quench,
until he brings justice to victory;
and in his name the Gentiles will hope.” (ESV)
In other words, Jesus' secrecy is part of his "gentle teaching" that will mold the minds of his disciples as Jesus moved "toward the cross and avoided the kind of public presence that would be more suitable to building an earthly kingdom."3
Other scholars such as Albert Schweitzer and James Dunn see the secrecy as an attempt to avoid Jewish preconceptions of what the Messiah was going to be. One of the most common expectations was that the Messiah would be a political and/or military leader. Jesus did not want to be that kind of Messiah and so didn't want people following him with that expectation only to be disappointed later. Dunn further states that Jesus was avoiding the temptation of taking that power and disavowing the false view of Messiahship.1 Zondervan's Exegetical Commentary also supports this view.4
Another possibility is that Jesus asked people to remain quiet in an effort to delay his own death. Messianic claims could cause the authorities to classify Jesus as revolutionary and execute him. In this view, Jesus had to wait until it was the "right time" to die and thus sought to reduce publicity (not just through the secrecy requests but also in various other ways). This view has the benefit of explaining why, in the climatic chapters of Mark's Gospel, Jesus directly declares his Messiahship for the first time - death is imminent.5
An element of both?
Despite the seemingly contradictory nature, some scholars have argued that both views ave an element of truth. Robert Stein, for instance, argued that Jesus did try to maintain a level of secrecy to avoid confrontation with the Romans. However, Mark then used these commands to show that the secret could not really be kept - the Messiah and Son of God titles of Jesus cannot be hidden, they are inescapable.1
The historical apologetic reasons, such as Werde's theory, seem implausible. Other historical-critical methods, while better than Werde's idea, generally suffer from the same problem - they disregard too much of the data. Quite often Mark follows the command to keep silent directly by a statement that the person did not do so. For example, 1:43-44 is followed by:
But he went out and began to talk freely about it, and to spread the news (ESV)
If Mark is responding to a critique that people didn't recognize Jesus as the Messiah during his lifetime, then it doesn't make much sense that he would also say people disobeyed the command.
Larry Richards further notes that in Mark 5:19, Jesus does tell a man he healed to "Go home to your friends and tell them how much the Lord has done for you" (ESV). The difference between the this instance and other can perhaps give us some insight on Jesus/Mark's reason for secrecy: in Mark 5:1-20, Jesus is in "the country of the Gerasenes," a pagan land. This difference could support a "redefining the Messiah" type theory (the people here not sharing the Jewish expectations) or could support views related to delaying Jesus death (there would be minimal threat of a Messianic insurrection in the foreign land, as compared to in Israel.)6
In has been suggestion that Mark himself provides a partial explanation in 8:27-33. In this passage Jesus first asks the 12 what people are saying about him, to which they offer various ideas - John the Baptist, a prophet, etc. He then asks who they say He is and Peter replies "You are the Christ." Jesus tells them tell no one about this, and then starts teaching that he must suffer and die. Peter rebukes Jesus, to which Jesus replies:
Get behind me, Satan! For you are not setting your mind on the things of God, but on the things of man. (Mark 8:33, ESV)
This could play into several theories - the expectation of man (earthly leader) is not a "thing of God"; the disciples learned his destiny so they could later comprehend what had happened (i.e. part of a teaching scheme); when the time was right, Jesus would reveal his Messiahship and die, but that time hadn't yet arrived. The Tyndale Commentary as this passage remarks:3
His destiny to die was revealed to them that they might understand the significance. The unveiling of the secret of Jesus' identity as the Messiah paved the way for the unveiling of the mystery of his destiny to die on the cross. The death of Jesus, which Peter so adamantly rejected, the church was called on the embrace.
Historical-critical explanations inadequately explain the data and can be dismissed. The literary device vs. actual words of Jesus distinction is generally harder to decide. In principle, most of the explanations could originate with Jesus to actually accomplish said aim; or they could originate with Mark to make the same point. To me, it seems that the "creation" of secrecy passages would be more likely to cause problems for the church than help it. A guy who is always telling people not to reveal his Messianic identity allows critics to say "even Jesus didn't claim to be the Messiah." Thus by the criterion of embarrassment I am inclined to think the words more likely originate with Jesus than the Gospel writers. Furthermore, if Mark was employing a literary device, he certainly didn't make it obvious (hence the large amount of debate on the subject).
Why, exactly, Jesus asked people to keep quiet (knowing full well they wouldn't) is hard to say. "To delay His death", "to teach to disciples", or "to redefine the Messiah" all make sense, but none provide a completely satisfactory explanation. Perhaps the best explanation is then that it was done for a combination of all three.
1Honor Among Christians: The Cultural Key to the Messianic Secret by David F. Watson
2A Theology of the New Testament by George Eldon Ladd, via Wikipedia.
3Tyndale Concise Bible Commentary by Robert B. Hughes & J. Carl Laney
4Matthew (Exegetical Commentary on the New Testament series) by Grant R. Osborne & Clinton E. Arnol
5A Commentary on the Gospel of Matthew by Craig S. Keener
6Baffling Bible Questions Answered by Larry Richards