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.
They also tend to ask a lot about things that might sound innocuous, like hobbies.
If I was being stupidly honest, I could talk about my involvement in the furry community. Most furries (~80%) are LGBTQ (versus ~3% to 5% of the base population).
Instead, I make vague allusions to being a gamer. (I play video games less than anyone I know, but it's not zero, so that's still technically true.)