So yes, Costco does make most of its profit by ensuring customers are happy and continue to renew their memberships every year.
This is financially illiterate because you're mixing revenue ("membership fees") with profit ("net operating income"). While it might be tempting to assume that membership fees is pure profit for them, it's not, because people only buy memberships because they're useful for something (ie. shopping at their stores). Therefore you can't strip that out from the other costs associated with operating a chain of warehouses.
I much prefer this to stores that are happy to burn customers, never expecting to see them again.
You think dollar general is making $37.9B (in 2023) of annual revenue from one-off customers? Unless you're operating a tourist trap, or some sort of business that people only need a few times in their lifetimes (eg. real estate agents), most businesses rely on repeat customers.
I have money to buy in bulk, care about quality, and am willing to make longer trips to stock up. The membership is trivial relative to annual groceries.
I think think the target market for dollar stores is the opposite
This doesn't make any sense. Costco makes a profit on the goods sold as well. They have every incentive to sell you as much stuff as possible. That's why they also engage in the usual retail tactics to increase sales, like having the essentials all the way in the back of the store, and putting the high margin items (electronics and jewelry) in the front. They might practice a more cuddlier form of capitalism than dollar general, but they're still a for profit retail business.