If you can afford it, then it's no harm really. I've made a profit from the lottery myself, albeit a minor one. Depending on the lottery, it's not the worst thing you can give pocket change away to for a bit of fun. So I never understood this "you'll never win" mentality/gatekeeping hobbies, people know the chances, but it's fun either way.
I think the big problem is that people who are addicted to gambling are being suckered several times a week. It's not really gambling, it's buying a daydream. If a casino gave you similar odds in one of their slots, it would likely be illegal based on the odds and the payout. So people who think of it like gambling are getting the worst of it. The expected value never approaches anything close to fair, even at rhe highest jackpots.
Entirely dependent on the lottery, the only one I have heard of this being a thing is the main US one. You can remain completely anonymous in the major European lotteries for example.
The US and Canada Lotteries publish the winners because it is a public record that they did in fact pay out. The European commisions that don't publish have to face yearly accusation that they don't actually pay out and then have to publish tax forms that do infact reveal the identity of winners.
How can you guarantee that? The chance is close to zero, but not zero - ergo you cannot be 100% sure that they won't win.
And that's the point they are trying to make - you don't need to be 100% logical to enjoy life. Sure, they probably won't win. But thinking they might, the anticipation of scratching the tickets, etc, is worth it to them.