There are a few different traditional orderings of the 10 commandments, so to be clear, we're going to discuss the commandment named in Exodus 20:7 (KJV): "Thou shalt not take the name of the LORD thy God in vain."
The original Hebrew words translated here as "take" and "vain" will help us understand the intent of this commandment. Take is from "nasa" which means to lift or to carry, perhaps implying a mishandling. Vain is from "shav" which means empty or worthless. This commandment warns us that God's name is to be treated correctly, with all the weight and respect it deserves. This applies to swearing, taking oaths, and definitely to cursing. The name specified here (as the LORD) in Hebrew is Yahweh, but the word "name" in the passage can also mean nature or character, so it follows that any reference to the person of God should be done with proper care.
Most people who say "Oh my God" use it as an empty exclamation to express surprise and even sympathy. It's almost a verbal tick and flies off the tongue without any meaning or invocation. My point is that you're saying the name you normally use for God without any awareness or regard. Unless the statement is addressed to God, the argument makes itself that in the way most people use it, "Oh my God" breaks the spirit, if not the letter, of this commandment.