That scenario is a good one except for the fact that the father already has custody, and with the mother being homeless and fresh out of rehab, chances are she'd lose. She'd have to became employed to have a chance unless he's abusing the little girl. She'd have to pay child support herself if she loses - which might actually be the case if he has full custody.
I'd venture to guess that's what this mother was wanting when she filed for custody is child support, otherwise she would not be living in a hotel room with a baby and no job. She'd have her baby. Am I judging? Yeah, women should stop having sex with men they don't know and having babies they can't afford because they are broke from buying whatever "substance" they're doing that lands them in rehab -- there are enough missing, dead, and broken kids out there because people have kids for the wrong reasons or just because they're careless. Of course I'm not talking about ALL parents of missing, abducted, or murdered children. 4 to 5 die by their parents hands every year....1 per year is too many.
Frayedknot gave an excellent analogy when she retold the story of King Solomon and the two women upthread. The one who loves the child for the right reasons should be the one with the child.