Courts are part of the government.
They enforce laws made by the legislator, they are made of people picked according to the law, they are the mouth of the law.
Many laws which infringed upon human rights have been enforced by courts, sometimes correctly so (in the lack of higher laws preventing such violations).
A law can be morally illegitimate but legally valid. It must be challenged politically.