A pedantic correction: “gender” appears to have had that non-grammatical meaning since the 15th century (and has also had an NSFW meaning as a verb since even earlier) but (if the OED is to be trusted, which usually it is) it’s true that “gender” became widely used to mean males/females collectively in the 20th century because “sex” was too distracting. (It wasn’t “sex” as a verb, though, but “sex” as a noun meaning “copulation”.)
A pedantic correction: “gender” appears to have had that non-grammatical meaning since the 15th century (and has also had an NSFW meaning as a verb since even earlier) but (if the OED is to be trusted, which usually it is) it’s true that “gender” became widely used to mean males/females collectively in the 20th century because “sex” was too distracting. (It wasn’t “sex” as a verb, though, but “sex” as a noun meaning “copulation”.)