Thus remove the religion from the mix and state a legal marriage is such and that is that. The groups can still have their marriage but it will not be legal and they may be punished as such.
So then, stop legally recognizing unions performed by non-government entities, and you've effectively removed religion from the matter. We wouldn't have to punish anyone anymore either.
That is almost the case now. Many places do not recognize any marriage not properly licensed by the government, but some still do. The common law marriage is one that would fit that definition and one most religions do not recognize either.
The option to have a legally recognized religious or civil leader perform whatever ceremony one chooses is available, but the key issue is the legal acceptance through the proper documentation.
For example, my younger son wanted one of his friends to officiate at his wedding, but there was some issue with that friend also just graduating from law school and wanting to pass the bar in this state before doing that. The solution was a legally binding civil ceremony and then a ceremony for the friends and family with the friend officiating but without the need to sign legal documents.