Temperature decreases as we go high in altitude. The same happens with Shimla, though Ludhiana and Shimla have approximately the same distance from the equator, Shimla is colder because it is high in altitude.
Not only the distance from the Equator but there are other factors like altitude, winds, ocean currents, and distance from Sea which regulates the temperature of a place.