Sarah has been rather passed around but I assume Debbie has signed the forms that gave Andy parental responsibility as the only time Social Services were involved was when Jo was going to adopt Sarah.
The Dingles let Diane take Sarah because Andy, despite his recent behaviour, is her father. They could have said no and got solicitors involved but at that point, they didn't know Debbie would be released soon. If she had stuck to her plan of pleading guilty to manslaughter, the judge in Sarah's case would give Andy a residency order.