Why would I buy something from Amazon when it's twice the cost of the same thing at Costco? I literally make up the cost of my yearly membership in 2 months of shopping there compared to any other grocery store.
Costco is not for everyone, though. I really can't use it for most of my shopping because it's just me and my wife and she won't commit to eating something specific for a week, but "meals for two, to be decided upon at 5 pm daily" doesn't fit well. We don't eat a lot of the staples they do have that are shelf-stable, and their freezer packages are big enough that to have any variety I'd have to not only like what's on offer but buy a chest freezer that I don't have a good location for.
The stuff they have is nice, but unless I'm going to go buy a bunch of steaks or something, it just barely pays for itself if that. I've let my membership expire and renewed when I had something significant to buy (in which case it's definitely worth it). For my life, it's cheaper to buy smaller packages of the things that will go bad like meat and produce, even at a higher per-unit cost, and it's much closer.
Now, Walmart Plus? THAT has been fantastic. It pays for itself quickly because they will deliver the items to me for the staples they have, and I only have to get one loaf of bread, one small jelly, etc. I don't have to drive out there, walk to the back of the store, pick out one size of paper towels, go pay for it, and drive home again. It's easy to put together a $50 order to get free delivery because it's all my staples in quantities I'll use, not only one or two in family-of-four quantities.
Because Costco is not universally cheaper. Costco discounts a few categories of products to lure you to shop there, but has higher prices in other categories. Fresh produce, meats, milk, and cereals cost more at Costco. Bulk packaged foods, frozen foods, and bulk household items are usually cheaper.
A lot of people don't notice this, and buy everything from Costco for the convenience, when it may be cheaper elsewhere.
For me personally, if I'm buying a large amount of meat, I buy from my local grocery store, as it's significantly cheaper.