U.S. law does not forbid foreigners from buying tickets or winning the lottery, and according to the Powerball website, "You do not have to be a citizen or a resident to play the game. You can be a tourist."
But if a foreigner buys a ticket, takes it home, and then tries to bring it back into the United States, they risk violating a law that forbids importing "immoral articles."
According to the law, "all persons are prohibited from importing into the United States from any foreign country any … lottery ticket, or any printed paper that may be used as a lottery ticket, or any advertisement of any lottery."