"Your Honor" or "Mr. (Mrs.) Mayor"
Salutations are gestures or greetings that are meant as an acknowledgment. The proper salutation for a current mayor is Mr. Mayor or Madam Mayor.
Mr. Mayor
madame mayor
The salutation for a former judge is typically "Judge [Last Name]" if you are addressing them formally.
You get to keep the title, so a former mayor is called "Mayor" or "Mayor Smith." (By the way, never refer to a former mayor as "ex-mayor." "Ex" is only for spouses and convicts.)
Dear Mr. Mayor or sometimes, such as New York, Your Honor.
'Dear Mayor Smith' is acceptable for ordinary communication. 'Your Honor' is a more formal salutation. In Canada (and, I think, in Britain also) it might be better to use 'Your Worship.' (A mayor historically had the powers of a magistrate.) Check with the municipality's office of protocol when in doubt.
ex-mayor
No honorific is required when addressing the former chairman of a committee.
Dear Mrs. Obama,
The former mayor of Bridgeport was P.T. Barnum.