This post sounds a bit chauvinistic but my point is simply to clarify the halacha and understand the Rambam.
The mishna says that a man comes before a woman for להחיות ולהשב אבדה, but a woman comes before a man for clothing and redeeming from captivity. However, if there is a threat of being sodomized, the man would come first.
The gemara itself doesn't offer any rationale to explain the order of the Mishna. However, the Rambam in the pirush hamishna explains that men are obligated in all mitzvos whereas women are only obligated in some of them, therefore a man is more "mekudash" than a woman which gives him precedence להחיות. The Shach (Y.D. 251:11) explains that the definition of להחיות is to save them from a life threatening situation, not about tzedaka because that is included in "clothing" where a woman goes first since her embarrassment is greater. This definition is also meduyak in Rashi who says that a kohen gadol who is anointed for war comes before a s'gan for the purpose of להחיות because he is more essential to the Jewish people. Rashi seems to understand that להחיות is speaking about saving them from a life threatening situation and we prioritize the one who is more essential for the klal.
The difficulty is the end of the Mishna that says if both a man and woman are threatened with sexual assault, the man comes first. The Rambam in his commentary to the mishna writes it is because a homosexual assault to the man is worse than a sexual assault to the woman since it is a דבר שאינו טבע לו - against the nature. The Rashash asks, why does the Rambam have to provide a new reason as to why the man should take priority over the woman - even if all things were equal the man would still come before the woman since he is more me'kudash? Perhaps the Rambam understands that kedusha is only a rationale to give precedence to a man when his life is threatened (and certainly his property - hashavas aveida). The point is that the one who has more kedusha should be given the precedence of survival, but in a situation where they are being threatened sexually and survival is not a question, the kedusha difference isn't significant.
Another question is that R. Moshe Feinstein writes in a teshuva (O.C. ?:49) that the kedusha of men is not greater than that of women. Rav Moshe supports this from the fact that all the pesukim that deal with kedusha treat both men and women equally. Even in the bracha of אשר קדשנו במצותיו women make it with the same nusach as men. Rav Moshe continues that any difference in obligation is just because that is the way Hashem wanted it, but is not reflective of a superiority of men over women. The difficulty is that the Rambam seems to say otherwise! Furthermore, the context of the mishnayos is that כל המקודש מחבירו קודם את חבירו which is learned from a kohen who has first priority due to his kedusha, and then discusses a man coming before a woman. The context of the mishna compels the peshat of the Rambam that men have greater kedusha since they are obligated in more mitzvos. How does R. Moshe ignore this?
On another note, the Ya'avetz (quotes in pischei teshuva y.d. 252:7) raises an interesting question. What would be if the threat is not physical but rather spiritual. The community has a choice to redeem either a boy or a girl, but not both. He suggests that perhaps we should save the girl since it won't just be saving her, but it would be saving generations of Jews since her children will be Jewish, whereas saving the boy would only by saving him. However, the Ya'avetz concludes that since the precedence is given to the boy for physical danger, it should certainly be given to him for spiritual danger and we pay no attention to the fact that the girl will have Jewish children.