Deuteronomy 16:18-17:13
You shall appoint magistrates and officials for your tribes, in all the settlements that the Lord your God is giving you, and they shall govern the people with due justice. You shall not judge unfairly: you shall show no partiality; you shall not take bribes, for bribes blind the eyes of the discerning and upset the plea of the just. Justice, justice shall you pursue, that you may thrive and occupy the land that the Lord your God is giving you. You shall not set up a sacred post--any kind of pole beside the altar of the Lord your God that you may make--or erect a stone pillar; for such the Lord your God detests.
You shall not sacrifice to the Lord your God an ox or a sheep that has any defect of a serious kind, for that is abhorrent to the Lord your God.
If there is found among you, in one of the settlements that the Lord your God is giving you, a man or woman who has affronted the Lord your God and transgressed His covenant--turning to the worship of other gods and bowing down to them, to the sun or the moon or any of the heavenly host, something I never commanded--and you have been informed or have learned of it, then you shall make a thorough inquiry. If it is true, the fact is established, that abhorrent thing was perpetrated in Israel, you shall take the man or the woman who did that wicked thing out to the public place, and you shall stone them, man or woman, to death. A person shall be put to death only on the testimony of two or more witnesses; he must not be put to death on the testimony of a single witness.
Let the hands of the witnesses be the first against him to put him to death, and the hands of the rest of the people thereafter. Thus you will sweep out evil from your midst.
If a case is too baffling for you to decide, be it a controversy over homicide, civil law, or assault--matters of dispute in your courts--you shall promptly repair to the place that the Lord your God will have chosen, and appear before the levitical priests, or the magistrate in charge at the time, and present your problem. When they have announced to you the verdict in the case, you shall carry out the verdict that is announced to you from that place that the Lord chose, observing scrupulously all their instructions to you. You shall act in accordance with the instructions given you and the ruling handed down to you; you must not deviate from the verdict that they announce to you either to the right or to the left. Should a man act presumptuously and disregard the priest charged with serving there the Lord your God, or the magistrate, that man shall die. Thus you will sweep out evil from Israel: all the people will hear and be afraid and will not act presumptuously again.