Answer is: mostly for treatment for syphilis and other venereal diseases, but also for other diseases: tuberculosis, pains of childbirth, constipation, toothache, parasitic infestations and was used as disinfectant.
This was a problem because mercury and most of its compounds are extremely toxic.