Also, even if every law was made in accordance with some perfect ethical system (whatever that would be), problems remain:
1. You can still do unethical things that are too small or too big for laws to handle. It's perfectly legal to cheat on your partner, or to mock a bullied child, or to form a political party that takes power and repeals laws you don't like.
2. Even for the things that are covered by laws, a superhuman AI would be able to find bizarre loopholes that obey the letter of the law but would be considered unethical by most people.