The Catechism in Questions & Answers

315. Is it a violation of the Second Commandment to swear while invoking the name of God?

In the Sermon on the Mount, Jesus forbade swearing. It should be understood that this applies to frivolous swearing in daily life, but not, for example, to taking an oath in a court of law.
If someone calls upon God as witness in a mandatory oath formulation (“So help me God”) in order to bring to expression his obligation to be truthful to God, he thereby publicly professes his faith in the omnipotent, omniscient God.