The story
From God + damn; originally, and sometimes still, a present subjunctive expression of a wish that God smite someone for their wickedness; compare also antonymous God bless, God bless you, and God love (someone or something).
Etymology from Wiktionary, CC BY-SA 4.0.