I am so glad you asked this question, as this movie was one of my favorites not only because of the subject matter but also because of the acting involved. Quite simply, YES, Sam was a good dad who deserved to have custody of his daughter as long as he received the needed help.
First, let's look at Sam as a "good dad." Even though Sam has a very low intelligence level (that of a seven year old), Sam is both well-rounded and well-adjusted. He loves his daughter and is willing to take care of her even after the homeless woman who is Lucy's mother refuses. As Lucy grows, there are heart-warming scenes where both Lucy and Sam discover the joys of reading together and begin truly learning from books. Here is another endearing exchange:
Lucy: Daddy, did God made for you to be like this or was it an accident?
Sam: Ok, what do you mean?
Lucy: I mean you're different.
Sam: But what do you mean?
Lucy: You're not like other daddies.
Sam: I'm sorry. I'm sorry. Yeah, I'm sorry.
Lucy: It's ok, daddy. It's ok. Don't be sorry. I'm lucky. Nobody else's daddy ever comes to the park.
Sam: Yeah! Yeah! Yeah, we are lucky. Aren't we lucky? Yeah!
Sam can handle the tasks of everyday life for himself. He has gotten this far. Further, he is able to handle the tasks of everyday life for Lucy (as in the scene where he takes Lucy to buy shoes or the one above where he takes her to the park). Almost all of Lucy's problems stem from school (and the judgement of others): Lucy's unwillingness to admit she is smart and Lucy's reactions to horrible teasing from classmates.
Now, let's approach why Sam deserves custody. First, Sam already has a support group: other people with disabilities who help each other through life. So far, this has led to success with Lucy. Second, Sam has already arranged for childcare with a neighbor when Sam is unable to tend to Lucy. However, the most important piece of evidence as to why Sam deserves custody is this: the foster parents who are chosen for Lucy RETURN HER TO SAM. Why? A daughter needs her father (and consequently, a father needs his daughter). In an effort of true altruism, the foster family agrees to help Sam parent Lucy. Sam, then, is simply a "person in need." He might have different needs than those who are poverty stricken, but he has needs just the same. Society steps up as a result and proves that it DOES take a village to raise a child. Let me go a step further, though, and say that even if that weren't the case, and the foster family wasn't altruistic, adequate needs could be provided through both social workers and the public school system. Sam would need someone to contact for help and also, perhaps, could be afforded home-school care (similar to the visits provided by willing teachers to very sick students) as continual for Lucy. There are more than one option, but put simply, Sam deserves to be the dad of the family.
Just to add a personal note, ... the love between Sam and Lucy absolutely cannot be denied. It's just that "sometimes it takes a village." The irony of this movie is that everyone is interested in the well-being of Lucy, ... even the characters who don't want Sam to have custody. This is the reason why Sam does, in fact, needs help taking care of his young daughter.