So, strictly speaking, that's not how UK law, at least, works. The court can absolutely compel you to say things you memorized - in fact, including encryption passwords. You can of course, physically, refuse, but you can be held in contempt of court, and jailed until you reveal the information, indefinitely. So not at all off limits.
Indefinitely jailing people to get a confession sounds like a midevil torture tactic. Is that a good balance of the Average Joe's right to privacy and privacy restrictions for fighting crime you speak of?
> Indefinitely jailing people to get a confession sounds like a midevil torture tactic.
That's very clearly not what I wrote. You can demand information this way, not a confession... People in the UK generally have a legal obligation to answer any questions the court has, unless they are themselves the accused. There are a small few other exceptions.