Because sex and gender mean two different things. Your sex, male or female, is basically your chromosomal make-up (XX or XY). Gender is the not just the physiological, but also the behavioural characteristics that distinguish between feminine and masculine.
Simply put, sex is biological, gender is a social construct.