It ultimately depends on what Congress said when the relevant law was passed pertaining to that form of discrimination, how the enforcing agency has written the regulations, orders that have been issued, and how the courts have interpreted the law and regulations.
EEOC Notice 915.002 states that
Under the Americans with Disabilities Act of 1990 (the "ADA"), an
employer may ask disability-related questions and require medical
examinations of an applicant only after the applicant has been given
a conditional job offer.
Such questions must be "job-related and consistent with business necessity". There is a statutory underpinning to this declaration, 42 USC 12112(d) that
The prohibition against discrimination as referred to in subsection
(a) shall include medical examinations and inquiries
and
Except as provided in paragraph (3), a covered entity shall not
conduct a medical examination or make inquiries of a job applicant as
to whether such applicant is an individual with a disability or as to
the nature or severity of such disability.
except that
A covered entity may make preemployment inquiries into the ability of
an applicant to perform job-related functions.
EEOC also says that
In general, it is assumed that pre-employment requests for information
will form the basis for hiring decisions. Therefore, employers should
not request information that discloses or tends to disclose an
applicant's race unless it has a legitimate business need for such
information.
Such inquiries are illegal in the sense that the EEOC "prohibits" it, and in the case of disability there is a direct statutory mandate to prohibit it. There is a legal principle, "Chevron deference", that says that the courts should defer to an agency's interpretation as long as Congress hasn't directly addressed the question and the interpretation is not unreasonable.
Title 29(A)(35)(B) states the standards for detecting age discrimination for entities receiving federal funds, and while age discrimination is illegal, asking a person's age is not prohibited by specific regulation. The EEOC provides this manual regarding general race and color discrimination, and the section on "Evaluating employment decisions", where they say
determining whether race played a role in the decisionmaking requires
examination of all of the surrounding facts and circumstances. The
presence or absence of any one piece of evidence often will not be
determinative.
So asking a person's race is not per se a violation of the law, but it is an act interpreted by the EEOC to be evidence of race discrimination. On the other hand, asking about disability is totally illegal so there's no "totality of evidence" to the process. The footnotes in the manual point to relevant case law: there is no case law that says "asking a questions about a protected category is per se proof of discrimination", but it can be used as part of a pattern of evidence.