Asking is different than demanding. They can't use it if they didn't receive an answer.
They can ask, and then the candidate can choose whether they want to answer or not. It may be beneficial to the candidate to answer, or they may not really care if the company knows.
It accomplishes the same thing but doesn't limit speech.
Sometimes a job candidate might even want them to ask so they can set the minimum bar of what they are looking for without appearing to bring up compensation first.
I would take the same stance with any of the other "can't ask" questions (they can ask, but can't demand).
BTW, there's no law that says an employer can't ask about religion, children, etc. The law says they can't discriminate. It's just recommended practice to not ask those questions to not give any evidence for a discrimination lawsuit.
The law says, "an unlawful employment practice is established when the complaining party demonstrates that race, color, religion, sex, or national origin was a motivating factor for any employment practice"
https://www.eeoc.gov/laws/statutes/titlevii.cfm
But exceptions are allowed when it is relevant to the job.
A casting director can certainly discriminate based on age, sex, etc.