The judge ordered the grocer to pay the union’s legal fees after it tried to claim the union had violated its trademarks.