Can I be convicted for having violated the law at a time when it was
Generally, yes, in any case where ignorance of the law is no excuse, which is the vast majority of criminal cases.
This could be a defense in the rare tiny minority of cases (e.g. willful violation of tax laws in the calculation of the amount due when preparing a tax return, or a law criminalizing disclosure of a class of documents with a certain kind of "top secret" type classification) where ignorance of the law can be an excuse (but even then, only if you 1) were actually aware of the ruling that found the law to be unconstitutional and 2) relied upon that ruling when acting the way that you did).
In any particular case, the constitutionality of a relevant law is a legal issue presented in that case.
Precedents from other cases help courts resolve that issue in your case.
But, this legal issue in your case isn't finally resolved until all possible appeals in your case have been exhausted.
Saying that a law is "unconstitutional in the 9th Circuit" but "constitutional in the 5th Circuit" is somewhat sloppy language and doesn't really mean precisely what taking those statements at face value would actually mean.