The related concepts of crime and law have a long history out of which has emerged a variety of legal systems and juridical forms that necessitate the existence lawyers. Lawyers are a highly trained professional class that is concerned with the study and practice of law, and a criminal defense attorney deals with law that concerns crime.
Specifically, a criminal defense attorney defends those who have been accused of a criminal offense. A criminal defense attorney prepares a case in an attempt to protect their clients’ civil liberties and have them declared not guilty. In lieu of that, a criminal defense attorney will try to have the sentence given be as light as possible.
The legitimacy of law, in political theory, extends from some kind of governing body. The state, as both a theoretical construct, and an actual existing body of government, has historically often been the force behind the legitimacy of systems of laws. In Western political philosophy, it has been argued that a state must be established to protect humans from each other. The role of the criminal attorney is to act as a mediator in disputes involving harm or other criminal acts.
From Western political thought emerged the concept of the nation-state, which pairs nationalist feelings of patriotism with the form of the state. The Revolutions of 1848 throughout Europe played a role in the increase of nationalism, as well as liberal democracy and the court systems we see in Europe and North America today.
Through this process of nationalism, nations each developed their own particular legal systems that share a common ancestor, but exhibit a wide range of variation that depend largely on the culture from which they derive. However, in cultures that allow people to defend themselves in a criminal court, a lawyer is absolutely necessary.
The presentation of documents and verbal discussions had to be coordinated in a hierarchical fashion, as the legitimacy of the law comes from above in the chain of command. The necessitated the existence of courts and judges. Courts serve as official meeting places for lawyers as well as opportunities for judges to decide cases. Some cases are decided by judges, but most criminal cases are decided by juries, whom the criminal defense attorney must convince their client is innocent.
In modern legal systems, lawyers are still under the authority of judges, who in turn must answer to the state; however, lawyers also have a larger role, because people are allowed to defend themselves in court. In criminal cases, a defendant can defend him or herself with legal representation. In a criminal court, a lawyer can prosecute or defend individuals or groups in the interpretation and enforcement of laws. The decisions of courts set precedents that increase the likelihood of future court cases being determined in the same way.
As you can see, this profession has a long history and could not have achieved its current form without the technology of writing and the accumulation of laws in their written form.