If the material that is being measured is hot, the transferred heat will cause the material in the thermometer to expand, changing its volume. If the material that is being measured is cold, the material in the thermometer will contract, also changing its volume as it cools. Once the material in the thermometer and what it is touching are the same temperature, no more heat will flow between the two objects. At that point the material in the thermometer ceases to change volume and the temperature can be read.
If you took a thermometer from inside a warm house and left it outside in the cold for a few minutes, at first the material in the thermometer would be at the same temperature as the inside of your house. Outside, the material in the thermometer would begin to transfer heat to the cold air. The molecules would begin to slow down and the material in the thermometer would begin to contract. Eventually, the material in the thermometer would be at the same temperature as the outside air, and it would stop contracting. Then you could read the temperature and know how cold it was outside.