When a company does this to me (and I've had Walmart do this) I go straight to customer service and return everything I've purchased. Bonus points when you have perishables that can't be restocked.
I also make it a point of lodging a complaint letting them know I don't appreciate being treated like a criminal.
------------
Business Insider: Walmart not liable after detaining customer who refused to show receipts
https://www.businessinsider.com/walmart-customer-refused-to-show-receipt-lawsuit-false-imprisonment-2023-6