Imagine a county that forbids ANY broker not registered with its national regulators from offering services in that country. Only a small number of forex and crypto brokers offer services to the US, and only a small percent of those are 100% legally doing so. The US isn't the only country that does this. Just to complicate things, Canada has similar regulations, but those are controlled at the provincial level, so a broker might be perfectly legal in some parts of Canada while not being able to legally serve people in other provinces.
Fewer countries forbid their companies from doing finforex type business with offshore clients, but, in the world of fiscal regulations, stranger things have happened. I have seen a number of real stock brokers (the ones where you buy and sell on the exchange and actually OWN the shares, not the CFD type offered by many forex brokers) that only offer services in their own countries. Stock trading is older than currency trading, and is usually far more carefully regulated.
Some countries are subject to international sanctions, so any transfers of money in and out them risks violating anti money laundering (AML) rules. Other contries (such as Cuba) are subject to US sanctions and the US has been known to take actions against companies that do business in those countries even though doing business there is not a violation of international law.
Believe it or not, there are ways to try to game the system on bonuses and affiliate commissions. Most of these would be avoidable if the brokers set up their rules in a more intelligent fashion, but that doesn't stop them from getting annoyed when one or more large groups in a country find a way to get guaranteed profit by exploiting loopholes. Sometimes this gets so bad that the broker decides that it's not worth doing business in a specific country instead of figuring out how to close the loopholes.