In Mark 1:34 we read that Jesus "drove out many demons, but he would not let the demons speak because they knew who he was." The parallel account in Luke's Gospel tells us that Jesus "rebuked them and would not allow them to speak, because they knew he was the Christ" (Luke 4:41).
There are probably several reasons as to why Jesus would not allow the demons to speak. First, Satan is called the father of lies (John 8:44; see also Genesis 3:4), and the demons who follow Satan no doubt reflect the character of their diabolic leader. Certainly Jesus would not want any testimony regarding His identity from a sinister, lying source. Moreover, one must keep in mind that some of the Jewish leaders associated Jesus with Beelzebub, "the prince of the demons" (Mark 3:22). Hence, allowing testimony from lying spirits might add fuel to the fire regarding that false claim.
A second possible reason for Jesus silencing the demons may be to demonstrate that He has authority over the demons. This would be in keeping with other verses in the Gospels where this authority is openly demonstrated (for example, Mark 8:33; 9:38; Luke 10:17).
A third possible reason for silencing the demons may relate to the popular misconceptions of the Messiah held by many in first-century Judaism. The Jews were expecting the coming of a glorious conquering Messiah who would deliver the Jews from Roman domination. If a demon prematurely blurted out that Jesus was the Messiah, the Jews who were present might interpret the term "Messiah" in this mistaken sense. It may be, then, that Jesus silenced the demons from revealing His identity at this early juncture so that He could, in His own time, demonstrate by word and deed that He was the true biblical Messiah.
Finally, we might observe that it was Jesus' purpose not to have His identity established by the testimony of lying spirits, but rather by the messianic signs (miracles) that He performed (see Matthew 11:4-6; Luke 7:21-23). These miraculous signs were predicted of the Messiah in the Old Testament (see Isaiah 29:18; 35:4-6).