Photos, notes and messages locked in an account are hard for family to get at when someone dies. Apple lets you name a person for exactly that, and it takes a few minutes.
iPhone: Settings > [your name] > Sign-In & Security > Legacy Contact
Mac: System Settings > [your name] > Sign-In & Security > Legacy Contact
Tap Add Legacy Contact and pick someone from your Family Sharing group or from your contacts. They get an access key. They can store it on their own Apple device, or you print a copy and hand it over. Keep that printed copy with your other important papers.
Later, your contact asks Apple for access with that key and proof of death. The documents Apple wants differ per country or region.
I like that nobody learns your password this way, and your contact has no access while you are alive. Writing the password on a note in a drawer does neither.
You need two factor authentication on and a recent enough system (iOS 15.2 or macOS Monterey 12.1 or later). Do tell the person that they are your contact and where the key is. A key nobody can find is worth nothing, and Apple warns that without it the request cannot go through this route.
Further reading: How to add a Legacy Contact for your Apple Account