There are many types of laws. If a person is not aware of the existence of gravitation, he will still obey it and fall to the ground from a tall building. This is a law of nature and, indeed, ignorance serves as no protection and cannot shield one from its effects and applicability. But human laws cannot be assumed to have he same power. They are culture-dependent, history-dependent, related to needs and priorities of the community of humans to which they apply. A law that is dependent and derivative is also contingent. No one can be reasonably expected to have intimate (or even passing) acquaintance with all things contingent. A special learning process, directed at the contingency must be effectuated to secure such knowledge.
Perhaps human laws reflect some in-built natural truth, discernible by all conscious, intelligent observers? Some of them give out such an impression. "Thou shalt not murder", for instance. But this makes none of them less contingent. That all human cultures throughout history obtained the same thinking regarding murder - does not bestow upon the human prohibition a privileged nomic status. In other words, no law is endowed with the status of a law of nature just by virtue of the broad agreement between humans who support it. There is no power in numbers, in this respect. A law of nature is not a statistically determined "event". At least, ideally, it should not be.
Another argument is that a person should be guided by a sense of right and wrong. This inner guide, also known as the conscience or the super-ego, is the result of social and psychological processes collectively known as "socialization". But socialization itself is contingent, in the sense that we have described. It cannot serve as a rigorous, objective benchmark. Itself a product of cultural accumulation and conditioning, it should be no more self evident than the very laws with which it tries to imbue the persons to whom it is applied.
Still, laws are made public. They are accessible to anyone who cares to get acquainted with them. Or so, theoretically. Actually, it is inaccessible to the illiterate, to those who have not assimilated the legal jargon, or to the poor. Even if laws were uniformly accessible to all - their interpretation would not have been. In many legal systems, precedents and court decisions are an integral part of the law. Really, there is no such thing as a perfect law. Laws evolve, grow, are replaced by others, which better reflect mores and beliefs, values and fears, in general the public psychology as mediated by the legislators. This is why a class of professionals has arisen, who make it their main business to keep up with the legal evolution and revolutions. Not many can afford the services of these law-yers. In this respect, many do not have ample access to the latest (and relevant) versions of the law. Nor would it be true to say that there is no convincing way to pierce one's mind in order to ascertain whether he did know the law in advance or not. We all use stereotypes and estimates in our daily contacts with others. There is no reason to refrain from doing so only in this particular case. If an illiterate, poor person broke a law - it could safely be assumed that he did not know, a-priori, that he was doing so. Assuming otherwise would lead to falsity, something the law is supposed to try and avoid. It is, therefore, not an operational problem.