A judge has directed the Trump administration to withdraw television advertisements paid for with taxpayer money that served promotional purposes.