One obvious example would be if you had hired the interviewee in question. If so, it would be awfully difficult to demonstrate discrimination against them!
Don't get me wrong, it is a very bad idea to ask these questions. But it is not illegal, strictly speaking.
It is very common for confused employers to claim it is illegal, but as eli described this is an oversimplification and is not actually true.