The Lev Haivri* writes when the Rema was accepted as Rav in Krakow, there had a strange Minhag in the city.
The morning after a woman went to the Mikvah, the Mikvah Lady’s husband,
wished the husband (wife who went to the Mikva) ” Mazal Tov.”
The Rema held this Minhag to be boorish and non Tzanua, so he abolished it.
There was a person who was out of town and wasn’t aware of the abolishment of the Minhag.
One day he angrily approached the Mikvah lady’s husband and complained to him why he had not wished him Mazal Tov. The Mikvah lady’s husband answered
"For two reasons,
a) The new Rav abolished the Minhag
b) your wife never went to the Mikva that night”.
When the Rema heard this, he realized the reason for this strange Minhag.
He also realized his mistake and regretted having abolished the Minhag.
To compensate for his mistake The Rema decided to collect all Minhagei Yisroel.
Hence his Chibur of the Mapah on the Shulchan Aruch.**
- R. Akiva Yosef Schlesinger (Talmid of the Chasam Sofer)
** Story recorded in the Krakow Kehilla Pinkas(Journal
Source, with original Hebrew text can be found here