In the US, there are separate regulations pertaining to different forms of discrimination for employment, thus there is no one-size answer. For sex, 29 CFR 1604.7 states:
A pre-employment inquiry may ask “Male........., Female.........”; or
“Mr. Mrs. Miss,” provided that the inquiry is made in good faith for a
nondiscriminatory purpose. Any pre-employment inquiry in connection
with prospective employment which expresses directly or indirectly any
limitation, specification, or discrimination as to sex shall be
unlawful unless based upon a bona fide occupational qualification.
Let us take it for granted that sex is not a bona fide occupational qualification for an academic position. Thus the question is lawful only if there is a legal underlying interest. Suppose the question were "As a man, would you be able to able to effectively empathize with your nursing students?": this does not serve a legally allowed purpose, and only serves to indirectly restate a sexually discriminatory premise. This University of New Hampshire guidelines pages summarizes the basic interview prohibitions succinctly.
Notice that the language of the regulation is stated purely in terms of the existence of such an inquiry – it does not restrict such inquiries "as made by the CEO", or "as made by the hiring committee". It simply says that such an inquiry is not to exist. It is thus the university's obligation to assure that all administrators, faculty members, graduate students, undergraduates, staff members, and members of the general public who are allowed to participate in pre-hiring interviews know what kinds of questions are legal versus illegal.