Most laws are about intent. If you unintentionally did something you aren't prosecuted.
If you get a ticket for jaywalking, it may help if you can convince the judge that it wasn't your intent to cross the street, for example because you couldn't see the red light. But saying that you didn't knew it was illegal isn't a valid defence, not knowing the law doesn't protect you.
If you accidentally bring a gun into an airport and put it on an xray, you can claim you didn't know it was in your bag and get off.
At least you have a small chance to get away by claiming you didn't knew it was there. Your chance is zero if you claim that you put it intentional in the bag because you didn't knew it was illegal. Claiming not to know what is legal only works for corporations and government personnel because they can show that lawyers told them so.
(post is archived)