Noncitizen residents in the US are protected by the constitution. This includes the second amendment.
The second amendment talks about the right to keep and bear arms, not to purchase them.
They are free to buy them in the imaginary country they belong to, following their imaginary regulations.
An alien legally in the U.S. is not prohibited from purchasing firearms unless the alien is admitted into the U.S. under a nonimmigrant visa and does not meet one of the exceptions as provided in 18 U.S.C. 922(y)(2), such as possession of a valid hunting license or permit.
[18 U.S.C. 922 (d)(5), (g)(5) and (y)(2); 27 CFR 478.11 and 478.32(a)(5)
I was a bit surprised myself! Now to let my wife know she can buy me a gun for Christmas!