Simplest answer
I can think of a lot of juicy issues raised by your seemingly simple question, but I'm gonna keep it short.
State laws vary, but generally, a controlled drug possessed pursuant to a valid prescription is lawfully possessed. A controlled drug possessed without a prescription or possessed pursuant to an invalid prescription is not lawfully possessed. If you're in possession of juice you bought illegally on the black market (i.e., not pursuant to a valid prescription), the fact that you could have filled a prescription for the same substance lawfully (but chose not to) is not a legal defense.
It may sound harsh, but if you think about it, for the law to be written otherwise would make a prescription a "get out of jail free card." A junkie could get a prescription for a narcotic drug, stash it in his pocket, and then make daily trips to the corner dealer without fear of arrest (thereby both endangering public health and feeding the black market). Not something societally acceptable.