There are loopholes everywhere, and Facebook is not paying corporate tax anywhere including the UK and other places. It is not only the USA.
They do pay taxes. They play loopholes in numerous jurisdictions to avoid tax as much as possible.
Why do they do that? Because everyone else does. Also they have a fiduciary duty to do so. Yes, it's technically, actually, illegal for them _not_ to avoid taxation as much as possible because, well, then they wouldn't be doing everything they can to maximize shareholder value.