I'm assuming by "legal custody" you mean non-parental/third party custody (and not adoption or guardianship). You will need to file a Nonparental Custody Petition stating that 1) the child is not in the physical custody of one of his/her parents, or 2) neither of his/her parents are suitable custodians. The mother can join in the petition thereby agreeing that the court can enter an order granting you custody. Where is the child's father? If he is known, he will need to be included in the proceedings, either by joining the petition, or by giving him notice and an opportunity to respond. Even with both parents joining in the petition, there are several procedural steps that need to be taken before a permanent custody order can be entered and you would be well served to consult with an attorney in your area.
Sign up to receive a 3-part series of useful information and advice about child custody law.