Poor baby- you're a good mom to be concerned for this poor kid! The one thing I can say is : DOCUMENT EVERYTHING. You- and the grandma- both need to write down EVERY single time there is an incident that is bad for the child, whether physically neglectful or emotionally. This includes not being back when they are supposed to, any violation of the visitation agreement, anytime the child is not clean or well-fed, etc. You must write down everything, dates and times, to show the court that this is a pattern of neglect and not just a one-time thing.
Also, has the court appointed a guardian ad litem or assigned anyone to look out for the child's interests? This is supposed to be a third party, with no personal stake in the situation, who will be able to assess the situation.
Make sure grandma stays on GOOD TERMS with this person, no matter how frustrating this whole process can be. Anyone from the court or social services who is looking into things is in a position to be very influential with the judge according to what they report.
You may be asked to be a witness at a court hearing and to report things you have seen or changes you have noticed in the child's behavior. If this happens, don't trash talk the mom and dad- but say if you observed them intoxicated, etc. and that when they dropped off the girl she was dirty and told you she had not eaten, etc.
Be factual and make it clear that because your children are friends, you are concerned for this little girl and have observed first hand how she is obviously better off being cared for by her grandma.
Good luck and god bless! I hope this all works out for the best!!