Sugar is not necessary for pickling, but adds a sweetness to balance out the tart flavor of the vinegar and, in the case of pickled onions, the onions. You can try using more or less sugar when pickling onions depending on your taste preferences, or cut it out entirely to make keto pickled onions.