Lower compensation than private sector is not specific to the military. It is true of most government positions.
Typical offsetting factors that rational agents weigh include pensions, education subsidies and other benefits, job stability, and perceived upward mobility.