It appears that an IQ test can be administered if it can be argued that a certain score is required to do the job, and the test is not simply a way to discriminate. It sounds like a court case waiting to happen though: how does one prove what score is required? Easier if your defense is "we never administered an IQ test, tour honor".
The reason everyone doesn't test IQ is that it's not very useful, not that it's legally risky.
People think it is because there's an subtext that everybody would hire straight off IQ scores if they could, which supports a (frankly gross) biological essentialist argument a lot of edgy nerds are fond of. But the whole argument is fractally mythological.
The whole point is to have a test that is correlated with IQ, and does not look like an IQ test in a legal way.