The Gita is about maintaining harmony in the inner world and the law is about maintaining order in the outer world. Any Karma has two parts, one is the intent and another is execution. In the words of law they are called, using Latin words, mens rea and actus reus , respectively, in the context of crime.
For example, a surgeon and a murderer both plunge a knife into someone's stomach. The surgeon's intention is to save/cure, but the murderer's intention is to damage/kill. Death can occur in both situations, but the intentions are completely opposite.
Law is situational while the Gita is eternal. Driving on the left side of side of the road is legal in one country and may be an offense in another. Law is black and white, but not life which has many grey areas.
As long as one pays ( actus reus ) taxes, the law is not bothered about whether it was done with pleasure or pain ( mens rea ). Law is very comfortable as long as execution is within the defined parameters of law of the land. If someone is thinking of committing a crime, law wouldn't bar that, but the Gita says this thinking should go.
Bend the tree when it is young. Gita says, be aware about karma when it is at the intention stage i.e in the present and we don't have any control once it goes to execution, which is in the future.
While the focus of law is on execution, contemporary moral literature exhorts us to have good/noble intentions. But Gita helps us to transcend beyond intentions.
When, intention, good or bad, meets with success or failure, either Ahankaar gets a boost or internal build up starts like lava which would burst at a weak moment. Both the situations take us away from our inner self.
Just by observing ones intentions one can transcend them and reach the inner self.
Source - Daily World