Hypothetical question here: if I'm looking to hire a freelancer, is it legal to choose based on their country or language?
I would think you would be fine. I've seen people request things like this all the time. I would only worry if your reasoning is because you don't like another race or something, but even then I don't think there is much that can be done. I think it would be perfectly acceptable to ask for a coder say within the US, no outside country programmers due to the exchange rate and the laws that the coder and yourself could be held by if there was a breach in contract, etc.
Language could be a realistic barrier to the job and therefore I cannot see an issue with that Country is much more ropey grounds. If you dont want to employ someone from the UK because the weak exchange rate makes their job too expensive then the reason for not employing them is simply cost not their country of origin. If you dont want to employ someone from the UK because you think they are all scum then you have possible issues. The reality of the world however is that it is exceptionally difficult to prove prejudice cases as you can always simply say that the Indian/ USA/ Mexican or which every nationality supplier offered your prefered option (cheaper/ more experience/ larger company/ shorter timescales etc)