I guess there are a couple ways of looking at this.
Vets make a lot of money from the drugs they prescribe, so I could see why they would insist on selling them to you. On the other hand they are making good paying clients upset which is really a bad idea.
I don't know about legally but most wiill write prescriptions it seems. Sometimes there is a small fee. Ellie's vet has always written prescriptions when I've asked but then again I usually buy drugs from the office. I can't see her denying a script. We drop plenty of money there for other things.