If you are in the US, they cannot legally ask you for your gender. They can, and now often do, have a section that is supposedly for statistical tracking where they ask for gender, race and military experience. These are always optional.
As has already been stated, if information is required on an application, then your legal status is required. When I answer the optional gender questions, I use female - because that is how I identify and what I am (just not legally, yet).