That is one of the definitions that the Oxford English Dictionary provides for sex. It is not the only one, and it does not reflect the complexity and variety of definitions that are used in practice. The other definitions included in the OED include:
1b. A (notional) third division of humanity regarded as analogous to, or as falling between, the male and female sexes; spec. that consisting of: (a) eunuchs or transsexual or transgender people; †(b) humorously clergymen (obsolete); (c) homosexual people collectively.
2a. Quality in respect of being male or female, or an instance of this; the state or fact of belonging to a particular sex; possession or membership of a sex.
4a. The distinction between male and female, esp. in humans; this distinction as a social or cultural phenomenon, and its manifestations or consequences; (in later use esp.) relations and interactions between the sexes; sexual motives, instincts, desires, etc.
If you ascribe to the very narrow and prescriptivist definition of sex that essentializes the concept as reproductive ability, then you are left with the repugnant situation of declaring that postmenopausal women and women who have had a hysterectomy are no longer female and that sterile men or men who have had a vasectomy are no longer male.
It also explicitly leads to the conclusion that gender affirming surgery and hormone replacement therapy do, indeed, change a person's sex, as they necessarily alter a person's reproductive ability.