Typically at the end of a biography, you’ll see a note section that will indicate where the author got their info for each detail. You’d be amazed, if a person spent years, how much information they could dig up to tell the story of you. It’s not just what you remember, but your friends, family, coworkers, your social media posts, if you’ve kept a diary at all, etc. Also, if a person is a major figure (president, royalty, whatever), there’s a lot of information being collected and reported on during their lives. People will talk about their interactions with prominent figures in their own diaries, newspapers will report on the comings and goings extensively, all of that. It takes years to write a biography because authors will gather all this information and then take extensive time writing it into a cohesive story.
I think a lot of people have a sense of history in their correspondence. Even if someone is related to a prominent figure, and they’re writing them purely for enjoyment or normal correspondence, they might keep a copy of a letter they sent for posterity.
It also might be that they kept drafts for practical purposes. My mom keeps a draft of the yearly Christmas letter she sends to her cousins, so she can look back and see if she’s repeated herself at all over the years.
I think how awful it must be for historians when they know that diaries or correspondence were destroyed after a person’s death. So many spouses have burned diaries or letters after a death because of the pain or anger they feel. Such valuable historical records, lost because of a surge of emotion.