The line between what a judge can force you to divulge and what they cannot boils down to between what you have and what you know, respectively. A key, which is something you have, can be forced from your possession. As such, a judge can force you to provide a fingerprint in order to unlock your phone. However, a safe combination is something you know, and therefore immune from being compelled. As such, a phone passphrase cannot be compelled because it is something you know, not possess.
The distinction is that an object in your possession can be retrieved whether or not you remember that you have it or even know that you have it. It does not rely on your state of mind to be retrieved, and can be retrieved independently of your state of mind. Something that you know requires you to be in a fit state of mind in order for it to be retrieved; if there was no protection against an unfit state of mind, you could easily be jailed indefinitely for something you truly forgot about or did not even know about -- a horrifying travesty of justice that the abusive elements in our justice system could - and would - eagerly abuse.
Any judge who violates the balance of these two simple rules has no business being a judge. Full stop, no exceptions. Violation of this balance indicates gross incompetence and fundamental unfitness to be a judge.
As the old saying goes, better a guilty man walk free than an innocent man be incarcerated for even a single day.