Why did my garlic turn 'blue' when cooking?
This is the harmless result of two elements meeting in an acidic environment. The sulfur in the garlic (which makes your breath smell garlicky after you eat garlic or onions) combines with copper from the lemon juice and butter (in some areas, even water contains dissolved copper). The two elements react with each other, with the help of a few enzymes in the garlic, to make the blue-green color that you're used to seeing on the surface of old pennies. Heating the ingredients quickly or using older garlic to kill the enzymes should inhibit the reaction. Depriving the entire dish of copper will also prevent the discoloration. This effect is not harmful and it's perfectly safe to eat.

Based on an article by Esther Inglis-Arkell on  io9.com