There is no law that precludes a foreign national from purchasing a home in the U.S. Some mortgage companies do make it more challenging for individuals in nonimmigrant status to qualify for a mortgage.
I agree that there is no law preventing it, but beware that you may have to submit additional evidence of nonimmigrant intent next time you seek an F-1 or similar status because of the home you own in the United States. If you are going to keep it as an investment property after you leave and it will remain occupied that would help.