So, gambling is addictive, makes you spend more and more money, occasionally when you're lucky you get a big payout, though on average you lose. It is heavily regulated worldwide.
Gaming is also addictive, makes you spend more and more money, but there's no chance of a payout, ever. Completely unregulated.
Depends on the country and the type of lootboxes. In the Netherlands for example lootboxes with items that cannot be purchased or traded otherwise are legal. Lootboxes with items that may have monetary value are considered a form of slot machine gambling.
Overwatch Loot Box
In April of 2018, the Netherlands Gaming Authority conducted a study of 10 unnamed games, and concluded that four of the games were in violation of Netherlands laws concerning gambling. To be exact, the study said (via PC Gamer), "that the content of these loot boxes is determined by chance and that the prizes to be won can be traded outside of the game: the prizes have a market value." In order to sell such items in the Netherlands a license is required but given the current laws, no license can be given to game companies, so "these loot boxes (were) prohibited." The loot boxes used in the other games were deemed legal because they lack "market value." According to the study, those loot boxes whose prizes wouldn't be traded constituted a low risk for gambling addiction, being akin to "small-scale bingo." The marketable loot boxes though, those which are banned in the country, "have integral elements that are similar to slot machines."*