One comment outlines the issue rather clearly:
Once you have paid for your merchandise and passed through the checkout, they have no grounds to search you unless they have a reason to suspect you of theft.
Your bag at that point is your property.
The checking of receipts at the door done by many stores is actually in truth voluntary, though they hate it when people seem to realize this.
If you refuse, they can’t stop you.
I have a friend who makes a habit of doing this at Costco….
I personally prefer not to make a fuss – it just isn’t worth it to piss off some minimum wage drone.
It’s amazing the things I take for granted about how the world works.