I don't think it'd be illegal (in the US anyways). AFAIK only the employer is legally restricted as to what questions they may ask. I believe a prospective employee may ask any thing they want. What the employer responds to a question with might be restricted though.