For one of these two, a roof over their head and hot meals a couple times a day for a period of months is going to be extremely beneficial including in the long run, since they'll reliably be able to support themself thanks to the homeless shelter's infrastructure. For the other hypothetical case, it's still the right and humane thing to do for them, but the "bang for your buck" is lower to put it in crass terms.
If it just works out that women outnumber men in the former group, and the gender discrimination does a huge amount of work in selecting for the most efficient candidates to keep in the shelter, I'm in favor of the discrimination.