In Mark's Gospel, there are three instances of Jesus ordering demons into silence, Mark 1:21-28, 1:29-34, and 3:7-12. They form part of the 'Messianic Secret', in which Jesus is portrayed as commanding silence about his Messianic mission. It is a motif primarily in the Gospel of Mark, but elements of this have been copied into the later synoptic gospels (Matthew and Luke).
Most explanations fall into two main categories - that Mark's reports of Jesus' commands to silence are historically true, or that they were a literary creation by Mark's author, perhaps being intended to draw attention to Jesus' Messianic mission by the repeated commands to silence on the issue.
The earliest discussion on the Messianic Secret came from William Wrede in 1901. Wrede suggested that this theme was not historical but was an addition by the author of Mark.
Oxbridge Notes (Is There A Messianic Secret In Mark Notes) discusses Wrede's thesis and also looks at whether they can be explained historically. It puts forward the contention that Jesus wished to conceal his messiahship from men and women during his ministry for fear that it would have been misunderstood as a claim to political kingship, thus choosing the title ‘Son of Man’. The historical explanation is then criticised, in part because it leaves unresolved the problems of how the bystanders could ignore the confessions of Jesus’s identity made by the men and women who were possessed by these spirits.
Brennan Reed Hamil discusses the commands to secrecy in a student dissertation written at the Lubbock Christian University. Firstly, he says, there have been historical explanations. In line with this approach, the motive of concealment has been seen as a facet of historical Jesus’ own behaviour and teaching, which is correctly reported by Mark. Secondly, there have been literary or theological explanations, the basic thrust of which is to view the secrecy motif as a literary or theological device. In his summary of the commands to the demons (page 7), Hamil looks at how the literary structure of the passages emphasises the possession over the secrecy, and says the commands to secrecy may be a particular literary device that utilises the demonic possessions to emphasise Jesus’ divine authority.
In the overall context of Mark's Gospel, it appears that the exorcisms and the commands to silence were intended to emphasise Jesus’ divine authority. In this earliest New Testament gospel, only outsiders such as demons, the high priest and the centurion could refer to Jesus in such terms. By having the demons recognise Jesus, then having Jesus command them to silence, Mark was demonstrating to its audience that Jesus was divine, without placing the Christian evangelists at risk of attacks regarding blasphemy.