The big reason Walmart does not want to accept and Home Depot for that matter is that ApplePay is anonymized.
They want to track your buying behavior and market and sell to it. Home Depot is also concerned you might go with the default ApplePay card and not the Home Depot credit card. Target and CVS fortunately gave up on that.
The simple answer is what Whole Foods did and scan it a membership/barcode id before you ApplePay.
Apple pay is anonymized to the DPAN, which is a unique account number for a given payment card on a given device. It will be different depending on your device (for simplicity terms, say your physical card has number A, your iPhone 13 Pro Max has number B, your Apple Watch has number C, and btw you just upgraded that 13 Pro max to a 14 Pro Max, when you set up that card again instead of number B it's number D).
This makes tracking harder, but not impossible. Your transactions consistently made on one device (say your apple watch) will have the same DPAN (the account number stays the same per transaction, the EMV challenge/response is dynamic and securely tokenized per transaction). Target also has ways of associating multiple cards with what they term a guest ID: you might be IDed for an age restricted purchase and use your physical card on one purchase, and get IDed on a second purchase and use Apple Pay on your iPhone, they tie that to a common ID. Or you get emailed/mailed a coupon, they know who it was emailed/mailed to, use the coupon, use a form of payment, tie it back to the guest ID.
Similarly, Home Depot now asks about eReceipts, and it recognizes an email from a prior purchase if you use the same card. If Apple Pay were used (hypothetical being that Home Depot actually accepted Apple Pay), the DPAN wouldn't be the same per physical card, but it would be the same per device per card on a subsequent purchase.
The tracking bit is trickier with contactless digital wallets but it isn't why Walmart is refusing contactless (or Home Depot for that matter. For HD, it's just not a priority, and with little big box competition (basically just Lowes in most areas, and they don't take Apple Pay either), little reason to enable it. For Walmart, they hate the card networks and are sulking with WM Pay in the corner as a way to snub the card networks.