Gender can be grammatical, of course. It can also, says Collins, be used to describe the whole of a sex (ie men are the male gender). But an easier way to think of it is that sex is biological, and gender is social (hence the concept of lesbian/gay/bisexual/transgender, or LGBT). Encycopaedia Britannica says gender is "an individual's self-conception as being male or female, as distinguished from actual biological sex."
Depends on the form. Entry form for the Olympics should ask genetic sex. But in a wider context it is more sensitive to ask someone's gender because that gives a pre-operation transgender woman the option of putting female even though she still has male reproductive organs.