The legal basis is that companies which violate US sanctions are not allowed to operate in the US, or transact business using financial services companies which operate in the US. That applies even if no part of the transaction passes through US territory.
It's unfair that non-US companies must annoy Huawei. Non-US companies usually don't benefit from this. It's like forcing foreigners to be part of your army.
Those companies, like every company seeking to do business around the world, will make its judgment call on whether it's worth it to satisfy any party's demands.