Your understanding is wrong. God did not have sex with Mary. She was a virgin when Jesus was born. She was a vessel that God chose to bring Christ into the world.
Yes, I realize that...but does it matter? She was still pregnant...still in a scandalous position. Would G-d ever put a mortal woman in such a position? No. She still belonged to a man. The baby would technically be a bastard child since it wasnt Josephs. I know that sounds harsh but it is true. And would or could G-d violate his own Torah against illicit relationships? No. The whole thing is not moral by G-ds own word.