One of the first things they teach you in an intro to law course is what the courts focus on. The parts of an accusation include both the actus reus and mens rea. These translate to the guilty act and the guilty mind. Understanding these, your lawyer is able to focus in on why you are not guilty and why you do not deserve a punishment for your action. The prosecution will need to prove that your action was illegal (you had an actus reus) and that you knew what you were doing (you had a mens rea).
For instance, what you have been accused of may not be illegal in the way that you did it, or it may not have been you at all. A great understanding of the current laws is needed to deal with complex legal issues. Unfortunately, not knowing what you did was illegal is not an excuse in the eyes of the law, but it can play a role in how severe your level of your crime may be.
It is well known that a first-degree murder takes place when an individual plans and executes the killing of another. Second-degree murder does not include this planning; an individual may act out of emotion anger or fear. This lower level or degree is considered less severe, and while the act of taking someones life is clearly defined in the law, there is no justice in treating a pre-meditated and a spontaneous murder as the same.
The severity of your accusation is just one way that we try to understand and incorporate the human mind and understand why individuals act against the law, but what if you are not in control of your mind at the time of your guilty action? This dives into the realm of the insanity plea. If you are in fact not able to understand your actions as right or wrong and not able to understand the ramifications of your action then the law cannot justly find you guilty. Due to the complexity of our minds and the human psyche, cases that involve this defense often take a long time to present and be examined. Most of these cases find the defendant to be guilty in the end.
There are more variations of defenses including the gray area of justifiable crimes, such as self-defense, but this is better left to a lawyer to sort out.