How are laws and rules in harmony with the Dhamma? How are the laws and rules we make in harmony or in conflict with the Dhamma? How can one best practice Dhamma while also practicing law ,enforcing law or enforcing any rules?
You can read some advice given by the Buddha in DN16 in the section entitled "Conditions of a Nation's Welfare". There are many items listed like organizing and dispersing assemblies peacefully, living according to established rules, honoring the elders, protecting women, protecting Arahats etc.
You can also read "The Edicts of King Asoka" translated by Ven. Dhammika. For e.g. this verse from The Fourteen Rock Edicts:
I have had this Dhamma edict written so that my sons and great-grandsons may not consider making new conquests, or that if military conquests are made, that they be done with forbearance and light punishment, or better still, that they consider making conquest by Dhamma only, for that bears fruit in this world and the next. May all their intense devotion be given to this which has a result in this world and the next.
Regarding enforcing laws, King Asoka's Kalinga Rock Edicts state:
Beloved-of-the-Gods says that the Mahamatras of Tosali who are judicial officers in the city are to be told this: I wish to see that everything I consider to be proper is carried out in the right way. And I consider instructing you to be the best way of accomplishing this. I have placed you over many thousands of people that you may win the people's affection.
All men are my children. What I desire for my own children, and I desire their welfare and happiness both in this world and the next, that I desire for all men. You do not understand to what extent I desire this, and if some of you do understand, you do not understand the full extent of my desire.
You must attend to this matter. While being completely law-abiding, some people are imprisoned, treated harshly and even killed without cause so that many people suffer. Therefore your aim should be to act with impartiality. It is because of these things — envy, anger, cruelty, hate, indifference, laziness or tiredness — that such a thing does not happen. Therefore your aim should be: "May these things not be in me." And the root of this is non-anger and patience. Those who are bored with the administration of justice will not be promoted; (those who are not) will move upwards and be promoted. Whoever among you understands this should say to his colleagues: "See that you do your duty properly. Such and such are Beloved-of-the-Gods' instructions." Great fruit will result from doing your duty, while failing in it will result in gaining neither heaven nor the king's pleasure. Failure in duty on your part will not please me. But done properly, it will win you heaven and you will be discharging your debts to me. ....
This edict has been written for the following purpose: that the judicial officers of the city may strive to do their duty and that the people under them might not suffer unjust imprisonment or harsh treatment. To achieve this, I will send out Mahamatras every five years who are not harsh or cruel, but who are merciful and who can ascertain if the judicial officers have understood my purpose and are acting according to my instructions. Similarly, from Ujjayini, the prince will send similar persons with the same purpose without allowing three years to elapse. Likewise from Takhasila also. When these Mahamatras go on tours of inspection each year, then without neglecting their normal duties, they will ascertain if judicial officers are acting according to the king's instructions.
King Asoka's Seven Pillar Edicts talk about the hearing of petitions and the administration of justice:
Beloved-of-the-Gods speaks thus: This Dhamma edict was written twenty-six years after my coronation. My Rajjukas are working among the people, among many hundreds of thousands of people. The hearing of petitions and the administration of justice has been left to them so that they can do their duties confidently and fearlessly and so that they can work for the welfare, happiness and benefit of the people in the country. But they should remember what causes happiness and sorrow, and being themselves devoted to Dhamma, they should encourage the people in the country (to do the same), that they may attain happiness in this world and the next. These Rajjukas are eager to serve me. They also obey other officers who know my desires, who instruct the Rajjukas so that they can please me. Just as a person feels confident having entrusted his child to an expert nurse thinking: "The nurse will keep my child well," even so, the Rajjukas have been appointed by me for the welfare and happiness of the people in the country.
The hearing of petitions and the administration of justice have been left to the Rajjukas so that they can do their duties unperturbed, fearlessly and confidently. It is my desire that there should be uniformity in law and uniformity in sentencing. I even go this far, to grant a three-day stay for those in prison who have been tried and sentenced to death. During this time their relatives can make appeals to have the prisoners' lives spared. If there is none to appeal on their behalf, the prisoners can give gifts in order to make merit for the next world, or observe fasts. Indeed, it is my wish that in this way, even if a prisoner's time is limited, he can prepare for the next world, and that people's Dhamma practice, self-control and generosity may grow.