I just recently learned about this as well. Garlic contains Anthocyaninins, water-soluble pigments. With acid conditions, it may turn blue or purple. It also contains sulfur compounds, which may react with copper in water to form copper sulfate, a blue compound. Often occurs in jars of pickle, it is recommended to eat the pickles and discard the garlic.
http://extension.oregonstate.edu/jos..._solutions.pdf