My understanding is that the cases like bakers, caterers, and restaurants refusing to provide services for same sex weddings on religious grounds is that they are operating a public accommodation and if that particular state or community has an anti-discrimination law for the LGBT community, public accommodations must serve them. These bakers and whatnot are not a religious organization and cannot therefore claim religious protection.
If your friend is a deacon and somebody asks him to perform a same sex wedding in his church or as the deacon, he can refuse if it is against the tenets of that church and his beliefs.
If he were to become a mayor (or judge) and is still a deacon and somebody comes to his mayoral office seeking him to perform a wedding a same-sex wedding he would be on shakier ground refusing to but, if it's legal in the state, he would probably be advised by the city attorney to officiate the ceremony. His being a deacon of whatever church would be incidental, not integral, to his duties as mayor. I agree with you that if his possible duties as mayor would conflict with his personal or religious beliefs, he should probably not run for the job.