The ruling scores a win for a group of 21 attorneys general and three governors who sued over the Trump administration’s approach to grant terminations.