Judge Katherine Bacal’s decision ends a four-year legal battle over the humane society’s sterilize-and-return model.