Here are some of the possibilities:
1. Souls have genders and their soul-gender and body-gender didn't match.
2. They lived many past lives as male or female and weren't used to being male or female.
3. They planned a life as male or female and accidentally entered the wrong body by mistake, in haste, or without thinking it through.