During the 2008 crash, Walmart was one of the few companies whose stock didn't take a hit at all but Costco's share price dropped almost half. They both provide essential goods at rock bottom prices. What was the reason for the big difference in performance?
Costco supplies a very large number of small businesses. If a large number of small businesses go bankrupt Costco takes a big hit.
Walmart's customers are mostly individuals, some small businesses. A large number of small businesses going bankrupt will not be as big of a hit to Walmart.
There's also the issue of having a membership fee. Membership fees are one of the earliest expense that people tend to cut when they get into financial hardships. If your current options are to pay $100 for a membership to costco or buying essential items you need for your household the choice is very obvious.
Once people have stopped paying membership fees they will not go back to costco until they're reasonably sure they can still afford it a year later.