A high-profile trial of a woman accused of illegally aborting her baby collapsed due to “appalling and sloppy” reporting by the BBC, a judge has said.