> Historically, sex and gender have been used interchangeably.
This really isn't true. "Sex" was the only word anyone used for most of history; the idea that there's a distinction between "sex" and "gender" was invented by the sexologist John Money in 1955.
https://en.wikipedia.org/wiki/Gender#History_of_the_concept
"Gender" was originally a term from linguistics that had nothing to do with biological sex.