He DID obey the law. The charges they leveled against him were false. Neither Herod Antipas, the Roman tetrarch, nor Pontius Pilate, the Roman governor, could figure out what he'd done wrong. Pilate even wanted to release him.
The only reasons he was crucified were because the Sanhedrin, who were Jewish religious leaders and interpreters of the law, were angry with him for telling the people, truthfully enough, that they were hypocrites and for taking their power away from them. Bearing in mind, they wanted John the Baptist dead, too, for the exact same reasons. They didn't succeed in leveling formal charges against him because, 1. he never did anything they could twist into a criminal act, like they did with Jesus and 2. they were afraid, if they did that, the people, who loved John, would listen to them even less.