Jesus often commanded recipients of his healings not to speak of what had happened such as the references sited above and He also forbade the demons from revealing who He was. The injunction not to speak was to those who were not going to be travelling with Jesus. We know there were times when they disobeyed and this caused Jesus some issues (i.e., Mk 1:45). Jesus' own words shed light on why he didn't want people testifying to Him as found in His discourse with the Jews who were seeking to kill Him in John 5. In particular He points to the witness of John whom the Pharisees rejected but quizzed;
"You have sent to John, and he has borne witness to the truth. But the witness I receive is not from man, but I say these things that you may be saved" (Jn 5:34-35).
Jesus witnesses were to be the Father, His works as well as God's word (Jn 5:36-39). Every matter is established by two or three witnesses. The importance of Jesus' total reliance on these witnesses is why Jesus didn't announcing Himself as Messiah and certainly why He didn't want demons or men testifying. Such testimony would likely have compromised His mission. But more importantly, knowing Christ as Messiah comes by revelation of His person, His true nature. This can only be supplied by the Holy Spirit.
Then we come to Jesus' instructions to the recovered demoniac to tell all (Lk 8:39). Yes, this was Decapolis and not a place where Jesus was accustomed to go and why testimony in that area would not have hampered Jesus.
But it should be noted that in this instance a few other things also were different. Jesus allowed these demons to address Him for who He was, the Son of the Most High God (Mk 5:6, Lk 8:28, Mt 8:29). Why? He was training the twelve and this place was isolated. No one passed that way on account of the demoniac's violence (Mt 8:28). The disciples were already followers and there was no others to receive the testimony of these demons.
Then this man is set free of many many evil spirits after being tormented. Maybe 2,000, maybe 4.000, who knows? Whatever the number, such a deliverance was unique in history. One unclean spirit may conceal its evil work (they are masters of camouflage) in a person very well that no one may know except one who can discern spirits. And one demon could perhaps be put out by a Jewish exorcist or by prayer. And in such a case it may not even be talked about and even if it is perhaps those who hear won't place too much importance as one demon may not do a lot.
Mary from Magdala had 7 demons cast out which suggests her condition was very evident and was not recoverable without our Lord's intervention (Lk 8:2). She may have had an unclean spirit cast out by some Jewish exorcist only for it to return and brings others more evil than itself until her state became worse (Mt 12:43-45). That is, until Jesus set her free. It is notable that she then became part of Jesus' team and may not have had any injunction on telling her story.
What about a man with thousands of evil spirits? It is clear to all this man is totally overpowered, his mind if overthrown, and he is driven by the evil spirits to do many wicked things to others and to himself (Lk Lk 8:27,29; Mk 5:4-5).
And we know he was from the city (Lk 8:27) and likely everyone knew who he was and knew he was mightily afflicted. Therefore, for him to return and have no explanation as to his recovery because he was commanded not to testify by Jesus was then to put him in a position of serious disobedience toward Christ. This would have been a burden Christ would not put on any person so our wise Lord instructed him to tell all.