It’s called responsible citizenry. One of the responsibilities that comes with the privilege of living in a democratic society is that you be aware of who you are electing to public office and what laws they are passing. What exactly would the alternative be?
In essence, as an adult it is your responsibility to know what the law is. Education, which is publicly provided for you as a child, is meant, at it’s most basic level, to teach you how to be a responsible citizen.
Of course, this is all normative. In theory you are expected to know all applicable laws regarding any activity you choose to partake in.
In a descriptive sense, it is impossible know every obscure law. Suppose I’m traveling with my dog, and I spend the night in a small town that has an ordnance forbidding that any person walk his or her dog on a particular street between certain hours. (This is a law that I’ve actually come across.) If take my dog out for a walk at the wrong time, I may well be ticketed. In this case, if we assume that no signs were posted, I would argue that my ignorance of the law is a valid justification.
There was/ is an ongoing issue in Myrtle Beach, SC that I heard about while vacationing there last summer. In South Carolina, there is no law requiring motorcyclists to wear helmets. But the city of Myrtle Beach passed a law requiring helmet use. So people simply driving through were getting ticketed. There was a lawsuit going on over it. In cases where a particular city has laws that are contrary to the laws of the state, I think ignorance is a perfectly valid excuse, and a judge is likely to agree.
There is some leeway in the law. If you have a good lawyer, you can sometimes get out of certain things due to ignorance of the law, depending on the nature of the law and whether most people might reasonably do the same thing in the same situation that got you in trouble.