Render unto Caesar that which is Caesar's
In the U.S., the government cannot and should never require a pastor to conduct a marriage ceremony that the pastor finds morally objectionable.
However, a public employee must perform whatever task is required for that office.
Resigning from an office that requires activity that the public employee finds morally objectionable is certainly a valid decision to make.
What cannot be allowed is a public official collecting a paycheck and then refusing to do what is required as a condition of employment.