Why do thiols have such a propensity for bonding with mercury?
Well, sulfur in general, and thiolates in particular, are known for bonding very strongly to gold, lead and mercury. In the particular case of mercury, which was known very early in the history of chemistry (indeed since the times of alchemy), this is the reason thiols are often called "mercaptans", from the Latin mercurium captans (capturing mercury).

In Pearson's HSAB theory (hard and soft acids and bases), the reason the S-Hg bond is be stronger than the O-Hg can be explained because S2- is a soft basis and Hg(II) is a soft acid, making a good fit… while O2- is harder.

Finally, regarding the historical use of thiols to bind mercury (and lead to), let's just say a chelating agent for mercury and other toxic compounds was quite useful as an antidote. You can read a very nice book on the historical use of mercury and lead in John Emsley's The Elements of Murder.