The real purpose of the temperature sensor is to prevent damage to the chip and to make sure software running on the chip run correctly. All other uses are side-effects.
All electronics components have a maximum temperature before they start to fail. A high enough temperature will even damage a component (this is actually common sense, everything has a maximum temperature rating - even you: there is a temperature where you will start cooking and your brain will stop working).
Before being damaged, electronics components may produce unexpected results. Transistors may randomly turn on or off, conductors become more resistive etc. When it comes to a CPU, this results in incorrect execution of instructions. In most cases you will experience this as a crash. Crashing is lucky because in the worst case this will silently execute something you don't expect and don't crash but will silently do something bad to your data like corrupt a file on disk or damage an external device.
The old-school solution to this is to make sure your CPU never get too hot by using huge heatsinks and limit how fast you run your CPU. The more complicated solution is to monitor your system's temperature and slow down your CPU (thereby reducing the heat it generates) when it gets too hot.
Note: Slowing down the GHz works because CMOS circuits consume practically zero amps when not switching, unlike regular circuits that consume amps when just turned on. So for CMOS circuits if it is zero Hertz it consumes no current and produce no heat at all. For CMOS it is the clocking of the transistors that generate heat. The more times it is switched on and off the more heat it generates - thus heat is proportional to GHz and the number of transistors in use.
It does not really matter if the heat comes from the CPU itself or the environment. Too hot is too hot. If you run a PC out in the sun it should still throttle when the internal temperature is out of spec.