The Trump administration cannot cancel grants that have already been awarded simply because “program goals and agency priorities” have changed, a federal judge ruled Friday in a case affecting billions of dollars in grant funding to states.