One legal loophole the KY Clerk seems to have used is that she refused to grant ANY licenses. Thus, though her reason was discriminatory/religious, her actions were technically not.
She began by denying them to gays back on June 26th, then expanded to refusing to issue all licenses. It is on July 1 that four couples (two gay, two hetero) she had denied filed a lawsuit, and the court got involved.
When she phrases it as, "I will not grant any licenses because I must grant them to gays, and that is against my religion" she is in violation of both the Establishment and Equal Protection clauses. I presume she gave her reasons in court - I have not read transcripts. But, she made such a statement on August 31st, in response to the U.S. Supreme Court's refusal to grant her stay request:
"I never imagined a day like this would come, where I would be asked to violate a central teaching of Scripture and of Jesus Himself regarding marriage. To issue a marriage license which conflicts with God's definition of marriage, with my name affixed to the certificate, would violate my conscience. It is not a light issue for me. It is a Heaven or Hell decision. For me it is a decision of obedience. I have no animosity toward anyone and harbor no ill will. To me this has never been a gay or lesbian issue. It is about marriage and God's Word."
So, no shelter for her.
Among her duties as clerk is to process licenses along well-defined guidelines. As soon as she refuses, she's not doing her job. As soon as she gives those reasons, she's also in violation of Constitutional law.