The state of mind is indeed a factor in determining the seriousness of a crime; in fact the law speaks of a person having mens rea, or a "guilty mind." There are instances in which the killing of another person is not unlawful. To further explain the concept, homicide is defined as the killing of a human being by another human being. Persons who die as a result of legal execution die from homicide and this designation is listed as the cause of death. If one kills another as an act of self defense, there is homicide, but no crime. Self defense is in fact a defense to a criminal charge; so if self defense is proved there is no crime in the first place. Crimes committed in the heat of passion are not murder, but may be classified as manslaughter, typically voluntary manslaughter. Manslaughter is the unlawful killing of a human being by another human being without malice aforethought. It implies that one acted before one had time to reflect on ones actions. Murder is defined as the unlawful killing of a human being by another human being with malice aforethought. By its very definition, murder implies that the killing was planned and executed coolly and without passion, literally "in cold blood." It involves elements such as planning and lying in wait. The sheer gravity of such an act calls for the most severe penalty the law can impose.
Crimes should be distinguished by the motivation of the perpetrator because we are not solely concerned with the act when we define something as a crime. Instead, we are concerned with the intent of the actor. This intent can be the difference between an act that is a crime and an act that is not a crime or it can be the difference between a crime and a more serious crime.
Let us look at the act of shooting someone. If the you were trying to prevent the person you shot from harming you, your intent makes this self-defense and not a crime. If you shot them in the heat of the moment, it is murder, but it is not as morally bad as if you calmly plotted to kill them. In that case, it is first degree murder.
When we define crimes, we look at them partly as simple actions, but we also know that the motivation and intent behind those actions makes the actions more or less morally wrong. The more an action is morally wrong the more serious of a crime it is.