As others have said, with respect to the disciples, it’s because he didn’t want to be either executed before the time came (before his hour was fulfilled) or else proclaimed a king. The Gospels make reference to both. Furthermore, Mark most emphatically brings out this idea of the “messianic secret,” i.e. that Jesus kept his identity as the Messiah hidden but gradually revealed it as time went on, so that the Crucifixion and Resurrection would be the culmination of all that he’d taught.
As for the demons, Jesus likely silenced them when they’d reveal his name for two primary reasons: 1) Calling someone’s name indicates you have control over them, and he was deflecting any demonic claims of dominion over himself and/or 2) The demons were not worthy to proclaim who Jesus was, and coupled with the above reason about the messianic secret–he was to be revealed on his terms, not those of the demonic powers.