Anthropologists.
Gender is based on sex, but not necessarily wholly bound to it. One can certainly identify with a gender that isn't what one's sex is. In some societies, gender roles primarily assigned to a masculine sex can be assigned to a female, creating a third gender, and vice versa.
What does it take to be "male?" Y chromosome and male reproductive parts. That's sex. What does it take to be a "man." That's not so easily answered and must be defined within each individual society.
When there are accepted roles outside of the expected roles females and males play within a society, more genders are created.
I stand completely corrected. I had a different definition in my head for gender. A wrong definition. Thanks for learning me.