I don't think "straight up illegal" is quite right. More like discrimination is illegal and if they ask then don't hire you, then they're practically asking you to sue them. They might deny it of course.
Considered evidence of intent to discriminate. Defacto illegal.