John Locke argued that the main purpose of government is to protect the natural rights of its citizens. He believed that the government acquired this power through the voluntary consent of the citizens themselves.
Much of Locke's feelings about the purpose of government are laid out in his Second Treatise of Government. In this work, Locke explains how a government is responsible for protecting the natural rights of its people. Much of this is to be accomplished through the passing of laws and the enforcement of penalties for those who break them.
Locke imagined a hypothetical state of nature in which there is no authoritative power to protect the rights of the weaker and more vulnerable. Locke contended that civilization is dependent on the well-being of the entire populace. Therefore, some entity must exist to protect the rights of all its people. Consequently, a government is given its authority by the people who it aims to protect. This government is tasked with ensuring the common good by protecting the right to "life, liberty, and property" of its people.