Courts have actually ruled that this defense is invalid because of the impossibility that you would forget a password you enter several times a day.
EDIT: This comment blew up and everybody has a different snarky gotcha response so a few reminders:
1. I didn't write the law. Arguing with me over whether or not it makes sense won't solve anything. I don't even agree with it
2. The ruling, like most similar rulings, is specifically in regards to your phone PIN code, which a court once ruled is something you enter so frequently that you couldn't possibly forget it. Courts have generally ruled that passwords cannot be turned over to law enforcement if you don't want to give them, although obviously as we've just seen this is a rapidly-evolving area of case law. There is no settled precedent on this
3. Again, as stated above, if you use a password manager or some other form of encryption for your passwords, they will demand that you hand over the master password, encryption key, or whatever you use to access the password(s). And again, whether or not this is a lawful request is obviously up for debate
4. If you are actually in such deep legal shit that you need to desperately prevent the police from accessing your phone or hard drive, stop taking legal advice from people on ResetERA and contact a lawyer, the ACLU, and/or the EFF immediately. None of this is settled case law and you are going to need to fight for it in court