How does a temperature sensor gather temperature? What is the mechanism used?
More specifically I want to understand how the TMP102 sensor works.
The data sheet shows that it is a "diode" temperature sensor.
If you operate a diode forward biased with a known current, the voltage across it has a predictable change with temperature, about -2mV/K.
More likely they use a diode-connected transistor (which behaves more like an ideal diode) and probably operate it at two currents (alternating and typically about a decade apart) and look at the difference in voltage, which is more predictable over a wide range (but has output about 10% of the direct method, so about -200uV/K).
They also probably calibrate the temperature using EEPROM or resistor trimming at a single test temperature.
Unless they've published details of the above somewhere, they're IP of the manufacturer.
This kind of sensor uses a diode as a temperature sensor. A diode can be used as a temperature measuring device, since the forward voltage drop across the diode depends on temperature, as in a silicon bandgap temperature sensor (Wikipedia).
The value of the forward voltage is read by an analog to digital converter which makes digital data available through a serial interface.