They have various methods. One of the common ones is analyzing ice core samples. The ice sheets are accumulated over the years so each layer on ice sheets is from a certain historical period (much like tree trunks.) By analyzing the chemical status of the ice core on each layer, they can extract data, such as temperature, about a certain period.
Stack Overflow's CEO doesn't understand Stack Overflow (jlericson.com)
This month is the planet's hottest on record by far – and hottest in around 120,000 years, scientists say | CNN (edition.cnn.com)