Making fair sports competitions will always be a compromise - part of sporting competitions is inherently unfair, it is about who has the most genetic advantage.
In seeking such a compromise, we recognise some categories. In athletics, sex is one, and age is another in other sports, weight is also considered to be such a strong component that there are different categories for competitors in different weight classes.
Age is the reason there are junior championships (for people who are likely below their prime) and masters categories (for people who are likely above their prime). A 1:55 800m time is unremarkable for a 25 yo man, it is very remarkable for a 50 year old man, or indeed for a 25 yo female.
Age and weight are relatively easy to measure, although there is some ambiguity about both; the fighting weight for a boxer will typically be higher than the weight at the official weigh-in, and there are the occasional accusations of age-cheating. Sex is more difficult, but it doesn't mean we cannot do it.
At the moment, our system of equating sex with self-identified gender is primitive and clearly not up to the task. In the spirit of PCA, We should use a threshold in testosterone, or possibly a combination with other factors that most clearly bisects two (or perhaps more) categories of athletes, and that is clearly a dominant factor in performance; this is for sports scientists commissioned by IAAF to determine. It will not be perfect, but it avoids most of the current problems.
As stated earlier, in lower level competitions, for practical reasons, we can stick to the gender based categories, just as we have no drugs testing in those competitions (despite the rules disallowing drugs). Here we have to assume that a self-identified gender correlates with the competition category, just as we have to assume that an athlete competes without drugs.