“Holy mackerel” is what is called a minced oath, a phrase where an offensive term is replaced with a non-offensive one. In this case, turning a potentially blasphemous utterance into a silly or humorous one. There are a number of “holy X” ones: holy cow, holy Moses, and holy smoke