What you are describing is referred to as Delayed-Onset Muscular Soreness, or DOMS. Despite its ubiquity, the phenomenon is still not fully understood. However, amongst the many theories attempting to explain it, the literature suggests that delayed-onset soreness is most likely caused by a combination of muscle cell damage and acute inflammation.
The factors that contribute to the degree of soreness experienced are, by contrast, generally well understood—the most influential being:
- the novelty of the exercise
- its volume and intensity
- the amount of eccentric loading involved, and
- the size of the muscles involved
A high volume of moderate and eccentric loads tends to result in the greatest amount of subsequent soreness, particularly when exercise that is novel to the lifter. Smaller muscle groups tend to experience less delayed-onset soreness, possibly due to their (generally) greater fatigability—the consequence of their lacking coupled agonists and synergists that would allow the movement to continue.
It is notable that training protocol characterised accordingly is also closely associated with hypertrophy. Delayed-onset muscular soreness is therefore reasonably associate with hypertrophy.
However, the key to training effectively is not only to provide the ‘right’ stimulus, but to observe adequate recovery. It is the balance of stimulus to recovery, as described by the theory of super-compensation, that determines the effectiveness of our training. We should understand, therefore, that training is about proportion. Muscular soreness is not a good gauge of training effectiveness. Rather, it is a gauge of the optimal length of our recovery. We can train with high volume and intensity, resulting in signficant muscular soreness, then observe a longer recovery period. Or alternatively, and equally effectively, we can train with lower volume and intensity, resulting in only light muscular soreness, and train more often.
The second part of your question has a simple answer: the difference between a squat and a military press is the amount of physical work being performed, the size of the muscles groups being recruited, and consequently the amount of energy required to perform the action. Greater energy requires a greater amount of oxygen, and results in a greater amount of heat production.
I hope that helps.