Hehe, but it is!
Asking someone about their service status is done so that you can then choose to not employ that person to minimize your risk for absence, which would lead to people in the service being less likely to get jobs, which in turn would lead people to not want to be in the service because of the effect on their job prospects.
Asking women about their private life (are you pregnant, do you want children, do you have children) would cause professional women to maybe decide they didn't want any children because of the effects that would have on their job prospects, or to simply not apply for jobs. This would negate decades of slow progress in getting the workforce to be reflective of society.
So, by definition it is discriminatory to ask these questions, the effect will be discrimination, even if that is not the stated purpose of the question. An employer could, and many do, for instance hide behind arguments like 'trying to maximize productivity' or 'being worries about the children of the employee', but none of that holds water.
At the end of the day the employer is simply worried that someone is going to miss a couple of days work.
And it's true, there is a real cost to all this, if someone gets pregnant, has to take care of their kids because they're ill or gets called up for the service then the employer will have to find and train a replacement if the absence is long enough, or swallow the loss in productivity for a shorter interruption.
But the cost to that business does not trump the cost to society as a whole if we let people pick and choose on those criteria, that is why it is illegal.