I mean I'm trying to think of other instances of getting access to evidence, and the only things I can think of is companies having to provide certain administrative documentation that may not even be their own. But that's probably me lacking imagination.
I think it hinges on if the search for the hard drives is for specific files or exploratory. IOW "we saw traffic that led us to believe he downloaded this specific piece of CP on this date and we want to verify its there" vs "we believe there is CP on his hard drive based on testimony from this person who said he shared CP with that person".
But the case law for this is super complex and changes by jurisdiction.
But if a judge tells you to unlock the hard drive they will 100 percent throw you in jail until you unlock it. For years even. If what they did was "illegal" then there will be no consequences for the judge.
Say, for example, you were a low level drug dealer and the court wanted evidence from your phone to convict your boss/supplier/whoever. They could compel you to unlock your phone, but could not use the evidence on it against you, only against your supplier, thanks to the 5th Amendment.
If you invoke your Fifth Amendment right not to self-incriminate you can be served with Statutory Immunity and then forced to testify, with contempt charges if you fail to testify.
There are also several different types of voluntary immunity, which is what you're describing. Those can't be compelled because they may not prevent the government from using your testimony against you in other venues, statutory immunity does not.
I think a lot of people have this idea of courts being highly technical and finding cases with precision, but in real life it's a lot more lazy and stupid people trying to avoid having to do work while still getting their job done. A great many miscarriages of justice come down to "the guy didn't want to do the work and lied about it, and nobody wanted to make the effort to verify what he said". There is a pervasive attitude of "that guy must be guilty, even if not this crime then of something, I'm not going to let him go over a mere lack of evidence. Society will be better with him behind bars."