“Illegal” is not the same thing as “sinful.”
An action is illegal if it contravenes a law established by man, such as the statutes of the Federal, state, or local governments (or whatever juridical order the reader belongs to).
An action is immoral (or objectively sinful) if it contravenes God’s law, which need not coincide in every case with the human law.
Note that, in order for a person actually to commit a sin, he must, evidently, know that what he is doing is wrong (i.e., a contravention of God’s law), and be free to perform that action willingly (e.g., someone who commits a bad action at gunpoint is probably not guilty of a sin).
However, all things being equal, we do have a duty to obey the just laws that are established by our government. That is because, as St. Paul explains, governments receive their authority from God, and when they rule justly, they are actually ruling on behalf of God:
1 Let every person be subject to the governing authorities. For there is no authority except from God, and those that exist have been instituted by God. 2 Therefore whoever resists the authorities resists what God has appointed, and those who resist will incur judgment. 3 For rulers are not a terror to good conduct, but to bad. Would you have no fear of the one who is in authority? Then do what is good, and you will receive his approval, 4 for he is God's servant for your good. But if you do wrong, be afraid, for he does not bear the sword in vain. For he is the servant of God, an avenger who carries out God's wrath on the wrongdoer (Romans 13:1-4, ESV).
However, the submission to authority that St. Paul talks about presupposes that the authority is acting justly. If, on the contrary, a government were to mandate doing something objectively sinful (say, for example, a law that makes it illegal to serve citizens belonging to a certain race), then it would actually be the duty of citizens to disobey the civil law; God’s law is always higher than man’s law. Indeed, an unjust law (such as the one in my example) is not really a law at all. This idea is supported by the following passage in Acts:
And the high priest [a legitimate authority in Jerusalem] questioned them [the apostles], 28 saying, “We strictly charged you not to teach in this name, yet here you have filled Jerusalem with your teaching, and you intend to bring this man's blood upon us.” 29 But Peter and the apostles answered, “We must obey God rather than men” (Acts 5:27-29, ESV).
Note that laws are also unjust if they are excessively burdensome, or if they are impossible to fulfill; for example, a law that declares illegal something that is, in fact, good and holy. In such a case, there is not necessarily a strict duty to disobey this kind of law, but there is also no strict obligation to obey it.
In summary, the relationship between “illegal” and “sinful” can be characterized as follows:
- Any action that contravenes God’s law is objectively sinful. Only a small fraction of these actions are regulated by human law at all. In other words, many actions are sinful but not illegal as such.
- A just law should in general be obeyed (keeping in mind that no human law is perfect—there might be cases that the legislator did not forsee). Something justly declared illegal in the law would also be sinful.
- An unjust law need not be obeyed, and if the law actually promotes sinful behavior, it actually must be disobeyed. In this case, that which is technically illegal is not sinful, and might even be dutiful.
In all these cases, we are referring to the objective sinfulness of the actions in question; the person acting must also have knowledge and freedom in order to commit an actual sin.
UPDATE: I will address some of the other concerns brought up by the original poster.
The origin of right and wrong: the so-called “natural law”
The rightness or wrongness of an action does not have its basis in the legality or illegality of it. As I mentioned, legality and especially illegality depend on the explicit mention of the action in question in statutes.
However, the rightness or wrongness of an action is ultimately determined by God, not by the government. In fact, rightness and wrongness exist even in the complete absense of human law. As St. Paul says,
For when Gentiles, who do not have the law, by nature do what the law requires, they are a law to themselves, even though they do not have the law (Romans 2:14).
This is the Biblical basis for the so-called natural law: the idea that human nature itself (which is unchanging in time and common to all human beings) provides us with the information we need to know right from wrong. In this case the “law” that St. Paul is talking about is the Jewish Torah (which provided, among other things, the Ten Commandments to help guild the ancient Israelites’ morality), but the principle is applicable to any kind of law. I do not need the government to tell me that murder is wrong, although I am grateful to the government for making it a crime punishible by law. More importantly, it is not the government that makes murder wrong—God does that by creating us the way He does. Rather, the statute merely renders the natural law explicit.
That is why it is so important for laws to be just: if they do not conform to the natural law—to the morality that God has endowed in our very natures (which is what justice entails)—then they cause confusion and misery. And, as I mentioned, non-conforming (i.e., unjust) laws are not even binding, because in making such laws a state abuses the authority that God has entrusted to it.
Regarding some of the particular sins mentioned by the O.P.
Polygamy is a complex topic in the Bible, but it should be noted that it is only present in the early part of the Old Testament. We see it with some of the Patriarchs (Abraham, Jacob), in the Judges, and with the kings of Israel.
However, even in the Old Testament, there was a growing understanding in the People of Israel that polygamy is not in accordance with God’s plan. It was largely due to his polygamy that Solomon apostatized at the end of his life:
4 For when Solomon was old his wives turned away his heart after other gods, and his heart was not wholly true to the Lord his God, as was the heart of David his father. 5 For Solomon went after Ashtoreth the goddess of the Sidonians, and after Milcom the abomination of the Ammonites. 6 So Solomon did what was evil in the sight of the Lord and did not wholly follow the Lord, as David his father had done (1 Kings 11:4-6, ESV).
Clearly, part of the problem is that he married foreign women, but the situation would never have arisen if he had not married 700 wives (v. 3).
Moreover, we can see from all of the instances of polygamy in the Bible that it is not favorably seen by the Biblical authors. For example polygamy breeds rivalry among the wives or concubines: consider, for instance, the expulsion of Hagar in Gen. 21; the whole episode of Rachel and Leah in Gen. 29, and their in-fighting in Gen. 30; and finally the mistreatment of Hannah (the mother of Samuel) in 1 Samuel 1.
In any case polygamy seems to have fallen out of use in ancient Israel by the time of Christ, and it was certainly the expectation of all the New Testament authors that marriage was between one man and one woman, exclusively.
Hence, the immorality of polygamy preceeds its illegality. Laws that make polygamy illegal simply reflect the natural law in this regard.
Marriage in general
In a similar way, marriage as such is rooted in human nature, and is ultimately determined by God. The state has no authority to define what marriage is: “What therefore God has joined together [i.e., in marriage], let not man separate” (Mark 10:9, ESV).
The government acts unjustly if it attempts to define marriage in a way that is contrary to the nature of marriage (i.e., the pernament, exclusive union between one man and one woman).
Likewise, if a government were to stipulate that certain classes of persons should be sent to concentration camps, it would be acting unjustly. Citizens would not be bound by such a measure. (The state might, of course, compel such persons to enter a concentration camp by force, but that would be a most grave injustice, obviously.)
Conclusion: the state does not determine morality
In summary, the state absolutely does not determine the morality of our actions. Rather, when it is acting as it should, it merely reflects the morality that already exists, thanks to the human nature that God has given us.
In some cases, the state does have the authority to make decisions about things that are not set in stone (like which side of the street to drive on), and so in general those types of laws should be obeyed.
But laws can only be obeyed if they are in conformity with God’s law, as expressed in our human natures (i.e, the “natural law”).