Legal theory distinguishes between acts that are malum in se, inherently evil, and those that are malum prohibitum, breaking the rules. For example, we do not believe that driving on the left side of the road is inherently evil (any more than the Brits think that driving on the right side of the road is inherently evil). We do believe that murder, rape, theft, are morally wrong.
The law is the minimum standard of morality. Laws aren’t limited to things that are malum prohibitum—we make laws regarding acts we regard as malum in se all of the time. We elect representatives according to a democratic process, they legislate morality, and the courts interpret the laws.
If you’ve got a better way of doing it, I’m listening.
My point here is that it isn’t the job of the courts to determine what is moral. It is the job of the courts to determine what is legal. It is the job of the legislatures to enact what we believe to be the minimally acceptable moral code into law. It’s not a perfect system but we don’t know of a way that’s better all of the time and over time.