A judge found the decision to conduct widespread layoffs and cut programs at these agencies “undermined their ability” to perform functions required by law.