This wasn't decided on a whim. The court challenged Texas to justify the law on a rational basis and they couldn't do it.
The Court's first whim was the presumption, contrary to the 10th Amendment and its own 1986 decision, that it even had standing to hear the case.