Requiring that employees live at within X minutes of the job site - likely legal.
Forbidding employees from certain locations as a proxy for a protected class - likely illegal.
An example: during the sales tax wars many companies would refuse to hire from a state that would could the employee as a tax nexus. This is mostly gone now as the sales tax fight seems mostly over.
Is it? Even outside of sales tax, it's additional accounting overhead to handle the withholding and filing for states you aren't in. No idea how much, I would imagine it's dependent on the systems in use, but the organizational incentives for allowing and enabling it are probably horribly misaligned for many companies.
It's a hassle but not an huge one, and any company that is in a population center that straddles a state border already deals with this (think New York, Chicago, Portland, Minneapolis/St Paul) - once you can handle two states handling additional isn't that painful.
More importantly the COST associated is fixed per employee roughly - having an employee in another state doesn't usually change the amount of tax paid, etc - just who it's paid to.
This won't be entirely true, but it's close enough - and for companies with outsourced HR (think: ADP) it's even easier.
Any company big enough to have a significant number of employees that this applies to would be big enough to eat the cost (and probably already has offices/etc in multiple states as is).
The thing you're looking for is the legal doctrine of "Disparate Impact."
Discrimination against a protected class (like race) is illegal. Geography is not a protected class, and discrimination based on geography is not inherently illegal. But under the doctrine of Disparate Impact, a particular policy of geographic exclusion is illegal if it happens to have outsized effect on a protected class (and has no business justification).
Note that Disparate Impact does not require intention!
It seems in some cases, yes. For instance many police and fire departments require you to live within X miles of the station. It also wouldn't seem odd if a company decided to exclude remote workers from places in which the company does not have a nexus, to avoid further complicating taxes.
Except in America our neighborhoods are heavily influenced by race so I doubt you could legally ban against hiring from a neighborhood made up 90%+ African Americans.
Well, you wouldn't be sued because you banned hiring from the neighborhood. You would be sued for discriminating against a protected class under a paper thin veil of banning a location.