It's not about legal vs illegal, it's a matter of right vs wrong. Yeah, you're allowed to go and buy out the whole store (aside from most stores now having policies limiting items), but you probably shouldn't, because it'll likely be largely wasted and also means others can't get what they actually need.