In addition to the answer and the comment given, the use of mercury in thermometers had another advantage frequently used in the lab:
Mercury, as a metal, has a high electrical conductivity. Imagine two thin wires inside the capillary of your thermometer. One of them is fixed.
The other wire is can move along a threaded rod. Typically, this was realized via magnetical coupling to a freely rotating knob on top of the (hermetically sealed) thermometer. Upon heating, the mercury expands and finally reaches the upper wire previously adjusted to a particular working temperature. At this point, an electrical current may flow through the thermometer.
These contact thermometers, nowadays replaced by mercury-free electronic thermoswitches, once were the working horses in the lab when it came to controlled heating of oil baths or monitoring cooling circuits for uv lamps.