Morality determines right and wrong. The law cannot properly encompass moral behavior and at times, you get laws that are blatantly immoral or allows for immoral acts. Religion sets moral guidelines, but is often perverted to immoral ends even when it is against the religion's moral code.
Slavery is a good example. Both government and religion have supported slavers, but it is a moral wrong.