How was it handled before insanity took hold?
Good question. I don't know... but the law needs clear legal definitions for male, female, and the exceptions (X). Otherwise, the left will challenge it in court and/or find ways around it, and the insanity will continue.
Just thinking aloud here... Maybe the law should read (for example): "A person's sex or gender on legal documents must be their natural biological sex at birth. All persons naturally born with XY chromosomes and internal and external male reproductive organs are male. All persons naturally born with XX chromosomes and female internal and external reproductive organs are female. Only persons naturally born with XY chromosomes and female reproductive organs or XX chromosomes and male reproductive organs may be listed as X for sex or gender."