This use of "Holy" with swear words is a case of euphemism. It was once considered more offensive to say "Holy Christ" when there was no actual intention to call on the name of Christ. Hence, lesser forms were used, such as "Holy hell/crap/shit."
Euphemism has been used as long as we can tell to allow someone to say something that is otherwise offensive. When Christianity was more popular and taken more seriously, any uttering of God, Jesus, etc outside of the context of prayer or other religious ritual, was offensive. There was even a time when referring to God's wounds or God's body was also offensive. The word Holy seems to have found its way into cursing phrases all the same.
There is an innate desire to "curse" under certain circumstances, such as when you stub your toe, or drop your dinner, or get a terrible fright when someone jumps at you, to which you might yell, "Holy shit!" In this context, calling out to God is actually appropriate. You are terrified and you immediately have images of your safety in mind, which leads to prayers of all kinds. Yelling "Oh, God," in earnest is appropriate. But sometimes the earnestness is lost, even among the believers. They don't necessarily want to call out to God at this moment, but the exclamation still comes, though skewed. Why this innate desire exists remains unknown, but it surely does, and there is a wealth of studies on its affect on the psyche. One thing that is known is that the more taboo the curse the more effect it has.
The innate desire to curse and the religious bindings on certain phrases or words make for prime choices for when a cursing situation does arise. That's why there is an urge to yell out "Holy, Christ" when something startles you rather than "Mahatma Ghandi!" Born from that, we get all sorts of curses involving religious words. In decades past, your could only say such a thing in private company (somewhat today too), so less offensive terms were coined, such as "Holy Hell/Crap/Shit" et al. Any derivative of Holy something comes from this originally extremely religious phrase "Holy Christ" or "Holy God".