To answer that, let's talk about what insurance is for, and why it exists.

Insurance is a regular payment in return for a large payment upon catastrophe. The insurer sets the price such that they expect to make money. That means that it should be a money losing proposition for the insured. The insured is willing to pay for insurance either because it is required by law (for example car insurance), or because they cannot afford the risk of catastrophic losses.

It therefore makes sense for companies to take out insurance on valuable assets that they can't easily replace as a risk mitigation strategy. Valuable assets, including key employees. But if everything is priced correctly, insurance is still a money-losing proposition for companies. And therefore anything that companies can cover by keeping sufficient cash reserves and credit lines, they should. In particular for low-level employees, death is merely a minor contribution to normal turnover, and companies should find that they save themselves money by self-covering that cost without using insurance. And furthermore companies should only seek necessary insurance for real risks. Which means that valuable assets, including key employees, should only be insured for the company's expected loss.

There is one major exception to this pricing rule. And that exception is when the entity (person or company) seeking insurance believes that they have more knowledge than the insurer. Then they may buy insurance as a bet against the insurer. The history of insurance is filled with examples. And there is a constant cat and mouse game where insurers try to protect themselves against this risk, while still providing insurance at a competitive price.

One famous example is that unscrupulous ship-owners used to buy ships in bad condition, overload them with a valuable cargo, insure it to the hilt, then set them off into the sunset knowing full well that the ship was likely to sink with all hands on board. The fabled insurer Lloyds of London got was the first insurer to solve this problem. They would draw the "water line" around a ship that was loaded and quoted insurance rates based on where that line was. Which meant that they didn't sell insurance to unscrupulous ship-owners, and could offer much better rates to scrupulous ones.

Another example is that people really do buy insurance on a spouse, then try to kill said spouse for the insurance. Therefore insurance companies have convinced governments to pass "slayer rules" that allow them to not pay out life insurance if there is any hint that it might have been murder.

Now back to dead peasant policies. Whatever the details of the tax breaks that made Walmart think it could be profitable, if insurers have correctly priced the insurance policies, then Walmart is virtually guaranteed to lose money on those policies. The reason why is that insurance is a zero sum game, and insurers are in it to generate a profit for themselves. While the loss of low-level workers is a tragedy, Walmart has the reserves to cover its own financial risks. And certainly should not have an incentive to over-insure those workers to the tune of a decade of full-time pay. (And then maintain said insurance after the workers had stopped working for Walmart and there was no possible loss to Walmart from their death.)

Therefore the only logical reason for Walmart to buy all of those policies is that Walmart believes that it has more information than the insurers on the likelihood that its workers will die. And therefore the only logical reason to buy that insurance is as a bet that insurers are systemically mispricing those policies. If they don't have that information, why else would they spend billions on what is supposed to be a money-losing proposition? Insurers knew this, and that is EXACTLY the gamble that insurers were describing in their brief.

The various laws against dead peasant policies were passed on this theory. They exist for the same reason that slayer rules exist. Because insurers convinced politicians that it is a bad idea to give people a financial incentive to see other people die. And politicians agreed that this made sense.

The lawsuit that Walmart filed was not because Walmart disagrees with this characterization of its behavior. It is because Walmart was not informed by the insurers of tax laws that meant that it went from a straight bet about who better knew the statistics on Walmart's workers, to a guaranteed money-losing proposition for Walmart. (Because whether or not Walmart won the bet, it wasn't going to win to the tune of how much it had to pay in taxes.)