Easy: in a market economy, your salary depends solely on how much a developer like you can be had for, not on anything else.
So if you're a unique, highly sought-after expert, the country doesn't make much of a difference directly, because people like you a generally hard to find.
But for a pre-senior level, there's a lot of people available, so the amount the client is willing to pay is determined by how much other people like you (from a place like yours) are willing to work for, which obviously depends on the country.
And then there's the selection bias. If the reason you got found is because the client has been looking for developers in your country, chances are that the client is looking to save money and isn't willing to pay much. Those clients who are willing to pay more generally look in different places.
And finally, a US-based client working with a US-based contractor is protected by US laws, unlike when working with a contractor from a developing country with a less reliable judicial system.