There are ways to ask those without being illegal and these are employed quite frequently. Essentially any kind of probing into someone's private life should be off-limits.
> There are ways to ask those without being illegal
Strictly speaking, its not illegal to ask the question. However, because it is illegal to base hiring decisions on it, asking the question is legally dangerous in two ways:
(1) Asking the question in an employment interview is evidence which can tend to support that you intended to use it in a hiring decision, and
(2) The interviewee answering the question is evidence that you had the information, and thus the opportunity to use it in a hiring decision.
As a result, the usual legal advice is to strictly avoid asking the question: you can’t legally use the response, and by asking it you make yourself unnecessarily vulnerable. The idea that it is illegal to ask the question is probably a consequence of this.
Strictly speaking, its not illegal to ask the question. However, because it is illegal to base hiring decisions on it, asking the question is legally dangerous in two ways:
(1) Asking the question in an employment interview is evidence which can tend to support that you intended to use it in a hiring decision, and
(2) The interviewee answering the question is evidence that you had the information, and thus the opportunity to use it in a hiring decision.
As a result, the usual legal advice is to strictly avoid asking the question: you can’t legally use the response, and by asking it you make yourself unnecessarily vulnerable. The idea that it is illegal to ask the question is probably a consequence of this.