I think you're overlooking that this was not at all a scientific matter. It was a legal matter, and as much as we might want the law to be completely on the same page as science,
The question the Court had to answer was NOT what the science said. The question was what the representatives in the Legislative Branch wrote into law, *whether scientifically sound or not* as that's how the democratic process works in the US.
We are free to elect lawmakers that make laws following science or not, but if we do elect unscientific lawmakers, well, it's not an unelected court's role in our system to override the representative system.