"Gender" referred only to grammar before it gained its modern meaning. The modern meaning was introduced in the 1950s/60s to differentiate social aspects (gender) from biological (sex). Of course people then started using it to just mean "sex", but if you use social definition I don't think it's a bad name for the concept.
Are you sure? That’s almost the opposite of what I heard, which was that “gender” being used to refer to -inity arose as a euphemism to avoid using the word “sex”, because the word “sex” came to be more associated with specifically “sex-acts” (and that prior to it being used as a euphemism in this way, it essentially meant something like kind/type/sort), and only after “gender” began being used as a euphemism in this way, did people begin using it to distinguish between “gender roles” and “sexes”.