First of all: Am European. Neber stepped foot in the US, nor do I plan anytime soon given the current situation.
Second: With a name like "Costco Pharmacy" or "Target Pharmacy", I can only compare it to the stores here at home.
And here, pharmacies are usually seperate establishments. Some superstores, however, do have a pharmacy inside.
And it really is a pharmacy that just so happens to be inside of a store. It isn't like your run of the mill isle. It has its pharmacists - it can't dispense perscription-only medicine without them.
And since they pay healthcare professionals to essentially cosplay as store clerks, they have to pay them well. So the biggest cost is most likely the personnel.
Also, like any regular pharmacy they do carry any "regular" medicine. The uber-regular stuff like paracetamol and aspirin you'd find on regular shelves. Regular stuff requiring a consult is availiable OTC and prescription only drugs are availiable with a prescription.
And pharmacies, including in-store ones do carry everything reasonably possible. The rest is availiable upon request - they'll order it for you if you ask.
So not carrying a specific cheap and reasonably popular drug is a tell, and asking a clerk with a valid prescription would also probably yield a "we don't do that here" about ordering some to fill the prescription.
At least that's how it's done in Europe. And at Target from what I've heard. So then why would Costco be any different?