How does Android obtain battery temperature?
Every mobile battery has an inbuilt thermistor, (which is a transducer which varies its resistance with respect to its temperature) with which the charging circuit constantly measures the battery temperature. It can even prevent charging the battery if the temperature reaches dangerous level and by controlling its temperature, the life of battery is increased.

Mobile battery has more than two terminals, one of which is for this thermistor. See the image in my question asked in this site.