The gender listed on government-issued documents. It often takes a court order to change this gender but the requirements vary by the document in question and the government enity issuing the document.
Some examples of legal gender:
Your legal name
the gender on your birth certificate
The gender in your medical records
the gender on your passport