It might sound weird, but I really wonder why.
As far as I know, the American legal system is based on common law, which means (at least as far as I know,) there is no codified law but only laws based on precedent cases.
Then, why does America have some strict guidelines of punishments? like, punishment for second degree murder, first degree murder etc.
Your question is based on a misunderstanding of what a common law system is. It is true that in a common law system, such as the U.S., a great deal of law is created by judges as developed in cases (called case law, or just common law, depending on context). However, it has never been the case, in any common law jurisdiction, that all law is made by judges. Legislatures in common law countries have always made some law in conjunction with judges. As far back as 1275, the Parliament of England passed a codification of existing law.
In America, common law (i.e., judge made law) and statutory law (i.e., laws passed by legislatures) have always existed side by side. To say that America has no codified (i.e., statutory) law is completely incorrect. There is tons of codified law. The U.S. Code, for example, which contains 53 separate "titles," contains the permanent and general statutes of the federal government. It is absurdly long. Every single state also has its own codified law. So do local governments. Common law exists alongside this statutory law. Typically, statutory law is superior to common law--if the legislature passes a law that contradicts the common law, the common law rule is set aside in favor of the statute.
Statutory law in common law jurisdictions such as the U.S. is incredibly extensive. I think where your confusion may be coming from is how common law jurisdictions conceive the legitimate source of lawmaking power differently from civil law jurisdictions (at least historically). In civil law countries, especially after the French Revolution and the writing of the Napoleonic Code, the only legitimate source of law was the legislature. The "code" of a civil law country is the fountain from which all law flows, at least ostensibly (and putting aside things like constitutions for simplicity's sake). When judges make rulings on unclear issues not answered by the code, they are not considered to be "making" law, but rather interpreting the Code as it exists. In common law countries, however, it is perfectly legitimate, legally speaking, for a judge to create a rule of law without reference to any code (the ancient legal fiction is that a judge is merely "discovering" the common law, which exists somewhere out there in the ether, but this is just what I said, a fiction--and even judges don't subscribe to it much). To put it in the most simple terms: in a civil law country, only the legislature may make law; in a common law country, the judge and the legislature may make law, but the legislature gets the last say.
As for criminal law, I can briefly say this. Historically, criminal law was a largely common law matter--i.e., crimes were defined largely by judges in cases. This has changed dramatically as more and more states have codified their criminal law. The development of the Model Penal Code in 1962 by the American Law Institute (an influential organization of legal scholars) helped to accelerate this, and today more than half of all states have adopted some portion of it.
Sources:
Jerry Norton, Criminal Law Codification: Three Hazards, 10 Loyola U. L. J. 61 (1978)
John Henry Merryman, The Civil Law Tradition