Why are common people selected to be the jury in the USA? Shouldn't people that know the law to decide criminal's fate? Why pick just some twelve random people to be the jury and decide the outcome of a trial instead of people who have extensive knowledge of the law?
Because it's explicitly a jury of your peers
That is, every person is entitled to have their guilt or innocence decided by people "like them" - not kings, lords or, heaven forbid, lawyers.
The jury doesn't need to know the law and indeed, in many jurisdictions, lawyers are explicitly disqualified from jury service (hint: if you want to avoid jury service, get a law degree). The role of the jury is to decide the facts - what happened and whether that meets the prosecution's burden of proof.
The jury is told what the law is by the judge - that's their job. Most law shows on TV skip over the very important role of the judge's instructions to the jury. These usually go along the lines of (greatly abridged and paraphrased) "If you decide that X, Y & Z are true then you must return a guilty verdict but if any of them are not true you must return not guilty."
A very brief potted history of the jury system is contained in this answer: Why 12 Jurors, why not 11, 10, 9, 1?
Now, this is, according to those from common law traditions, the great truth and beauty of the jury system. To those from civil, sharia and other legal traditions: it's just stupid.
Because that is the goal in common law!
The US jury system is based on picking a group of "randoms" from the street that form a jury of their peers of the accused - That is what the US constitution demands after all in the 6th Amendment. Do note that a jury of peers is not a jury of people that share your characteristics (only one gender of the accused's background) but to be a cross-section of the population around.
This has been interpreted by courts to mean that the available jurors include a broad spectrum of the population, particularly of race, national origin, and gender.
They don't need to know the law, that's what the judge is for. They need to listen to the witnesses and see the evidence and then decide, based on a couple of instructions (which are pretty much checklists to go through) that then result in "This is X".
Juries are nonexistent in many civil law systems
In germany juries are absent. The judge is also leading the examination (as in, asking questions). Then they analyze the facts and come to a verdict themselves. However, at least in Germany, there are "Schöffen", which are best described as laymen judges. These are not just random people though, they get a (short) legal training (in some cases, just a leaflet) because they are acting as (assistant) judges to the law degree judges.
When the jury first began to be used in trials of criminals in England, back in the late 1100s, jury members were people from their local area who were supposed to know, either personally or by "common repute" (aka "what everyone knows") what the facts of the matter were. In effect they were a group of witnesses, there to say what the facts were (because they knew), after which the judge would say what the law indicated should be done based on those facts. In this role, a jury replaced a trial by ordeal or a trial by combat.
Later, as districts grew more heavily populated, and tolerance for "what everyone knows" declined, the role of the jury gradually changed. Eventually, the modern jury, whose members are supposed to know nothing about the facts until they hear the evidence in court, emerged.
But the modern jury is still supposed to determine what the facts of a case are, letting the judge decide what law applies to those facts.
So why was the jury not done away with when it no longer brought local information into court? In large part, because of the huge judicial and social inertial. Such changes were then slow and often resisted. (Trial by Combat was not formally abolished until 1819, following the case of Ashford v Thornton although the last clearly recorded trial by combat was over 200 years before that.)
Beyond that, trial by jury came to be seen as a strong protection of an accused against unjust or tyrannical charges. It has thus remained an important part of US law, although it is now far less common in the law of England and Wales, where it arose.
For more details on this, I recommend the chapter "Grand and Petty" from The Law of the Land by Charles Rembar (available as an eBook).
Trial by Jury was never designed to have its present effect, and originally it was an instrument of Royal Justice, intended to more effectively convict those the authorities thought dangerous. It has changed drastically in purpose and effect over some 800 years, while keeping its form relatively stable. In short, the modern jury trial is a historical accident.
Many laws refer to the concept of a "reasonable" person. For example, someone is negligent if they do something a reasonable person would not have done, or fail to do something a reasonable person would have done, and if damages occurred which a reasonable person would have perceived as a foreseeable consequence of the action or inaction.
It would be impractical for a legislature to try to anticipate and all possible reasonable and unreasonable actions and write laws that would classify every action as reasonable or unreasonable. Further, judgments of reasonable and unreasonable are apt to be somewhat subjective. On the other hand, if twelve random members of the public agree that an action is reasonable, that's a pretty good sign that it is, and if twelve random members of the public agree that an action is unreasonable, that's a pretty good sign that it isn't. If the jury can'tr reach a consensus, that's a pretty good sign that whoever would bear the burden of proof hasn't met it.
A related issue is that while there are many cases in which an otherwise-illegal act may be excusable, it's not possible for legislatures to anticipate all situations where they should be. If twelve random members of the public would all agree that enforcing a statute against a defendant in a particular case would yield a patently unjust result, they would have a right and duty not to do so. This duty should not be taken lightly, and many prosecutors and judges would prefer that jurors not know about it at all, but if e.g. twelve random members of the public would regard a certain fine as excessive, that fine is excessive and the jury would have the right and duty to prevent it from being illegitimately imposed.
The Jury is the last defense against bad laws – like those that violate the Constitution – so juries can acquit if they feel the defendant has been unjustly accused even if the statute is a law but that law violates the individual's natural rights. Being a jury of the defendant's peers means that they are more likely to be objective in such a decision. Being a legal expert should not be a prerequisite because a legal expert may love a bad law and may convict without judging the law itself through a constitutional lens.
I have had the same question myself, because to me it makes no logical sense to have a group of 12 folks decide matters of law when the judge is most obviously the expert. After researching this, I discovered the concept of Jury Nullification. To me, this makes trial by jury make sense.
As I understand it, a jury has the ability (and the right via the 6th Amendment) to decide not only the facts of the case, but also whether the law was applied justly, and whether or not the law itself is just. Because let's be honest, not all laws were or are just. This is our society's last safety check to make sure people are not unjustly convicted due to unjust laws or their misapplication. I think the Wikipedia article does a good job of explaining it.