The blue or green color that you see is caused by an enzymatic reaction and is perfectly harmless. Natural sulfur containing compounds in onion and garlic breakdown quickly when exposed to oxygen to give us the typical pungent flavors we associate with these foods. These react in an acid environment with natural amino acids to form the harmless colored pigments you see.
The age of the garlic may have something to do with the reaction. Some have found that storing the bulbs for 2-4 weeks at 70°F will decrease the likelihood for this color to form. Some have also suggested blanching the individual cloves in boiling water for a minute to inactivate the enzyme. This may have an affect on the flavor though.
Garlic and onions can also turn green if stored in the light for too long. This time the color is the result of chlorophyll formation. Chlorophyll is harmless, but bitter flavors may accompany the color change. So store all your onions and garlic away from the light.
What Causes Blue Garlic?
When garlic is pickled, you will sometimes notice that it can take on a blue or green hue. Blue garlic occurs for several reasons, and there are precautions you can take to help prevent it.
When acid such as vinegar is added to the garlic, it ruptures the cell membranes of the cloves, causing amino acids and sulfur compounds present in the garlic to mix. An enzyme, isoallin, is subsequently released. Isoallin reacts with the amino acids, resulting in blue pigments called anthocyanins. These pigments are naturally present in the garlic, and damage to the cells increases the amount of these pigments, and thus their visibility.
Garlic may also appear blue due to the type of garlic and the soil conditions it was grown in. Anthocyanins are present in greater amounts in some garlic cultivars than others, so these types naturally exhibit greater color. Acidic soil conditions can also increase these pigments, giving the garlic a bluish-green tint even before you begin the pickling process. There is as yet unsettled debate over whether immature or mature garlic colors more readily.
Finally, the presence of metal traces in the water of your pickling solution can also affect the color. Copper, for example, will combine with the sulfur compounds in the garlic to produce blue-hued copper sulfate. A blue-green tinge can also be caused by metal equipment, including aluminum, cast iron, and tin, used in the pickling process.
To help avoid discoloration, use distilled water to ensure an absence of trace metals. Use a salt that does not contain iodine, such as Kosher, since iodine will also cause color changes; avoid table salt. Finally, like most pickles, garlic needs to be kept out of the sunlight. Sunlight will prompt the formation of chlorophyll, making the garlic turn green.
Sometimes your garlic will turn blue no matter what you do, but it is not something to worry about. The garlic is perfectly safe to eat, and will retain the same taste. In fact, in parts of northern China, pickled garlic is encouraged to turn as blue as possible to produce Laba pickles, a garlicky delicacy served during the New Year