There are, as the question correctly states, laws that govern nation-states. Almost all nation-states have, for example, agreed to the so-called Geneva Conventions, which essentially lays out the laws of war. These include prohibitions on the use of chemical weapons, rules about the proper treatment of prisoners, and many others. There are some gray areas about who is held responsible for violating these crimes—typically it has been individual military leaders—but these laws do exist.
Terrorism is by definition illegal under international law. That is, terrorism is itself a crime, though the United Nations has been unable to come up with an agreed-upon standard for what terrorism actually is. Where war crimes committed with state authority have been tried in international courts, terrorism is often domestic in nature—the Irish Republican Army acting within the United Kingdom, for example. In this instance, offenders were tried and punished within the UK legal system.
However, state sponsorship of terrorism is contrary to international law and has been used as a justification for military action in recent years. The Taliban regime in the nation-state of Afghanistan, for example, was attacked by an American-led coalition due to its support for the Al-Qaeda terrorist organization, a non-state actor. Another tricky issue in international law is defining (and therefore figuring out how to assign responsibility for) state terrorism. This might be defined as acts of terror carried out not by independent actors with state support, but by state agents or proxies acting on behalf of a state. Non-state actors are not subject to laws or agreements governing state conduct, but there are many layers to this issue.