Same with gender. Doctors observe a flavor of genitals, make a reasonable assumption, and legally assign the gender which seems appropriate.
Which could then become rather complicated if there are laws saying the sex assigned at birth has significant lifelong legal consequences.
So in practice clerical errors cause all kinds of long term havoc. Once declared dead it can be a monstrous effort to prove to various systems you are in fact alive.