In real life, if there was a masked vigilante whose codename is ‘Watcher,’ he’s a non-lethal masked vigilante who is a witness to a murder. The detectives and prosecutor want to put the vigilante on the witness stand, but the vigilante’s secret identity is, well, secret, and he doesn’t want to reveal it. Can he still testify with his mask on or testify anonymously?


This actually did happen in Seattle, Washington. There are quite a few real life “super heroes” that dress up and patrol their respective cities. This one was named Phoenix Jones and he had the whole comic book hero costume and everything. There was a law that allowed people to fight as long as both people consented called Mutual Combat and that played a big into allowing him to do what he did.
But he did end up being pulled into court and they forced him to de-mask himself and reveal his true identity. He even had an “origin story”, though not as dramatic as something like Bruce Wayne, but still. He’s an interesting character to look into.
Consider my comment as just a brief summarization of this whole thing as an answer to your question.
I think this depends on which region the court is in, but like in the US, if the hero is the defendant or plaintiff, I don’t think any court would allow the hero to remain masked and without showing their identity. Best they could do is only reveal to some parties involved in the court case, but the identity is still exposed. I think the only exception may be if the hero is a witness, and even then, maybe not and would need to identify to some involved in the case. This is because many courts around the world require people to know who their accuser is and lawyers often will try to fight against this since a secret identity cannot be truly verified for the best results in a court determination.