Up until the court decided to start ignoring centuries of legal tradition that is the bedrock of our legal system and threw out stare decisis the decision was actually more secure than a specific law.
Any law codifying it can be challenged on many grounds, especially the 10th amendment. It could easily have been struck down as unconstitutional because the federal government has no power to pass a law affecting this issue, since the constitution doesn’t grant it.
Only a constitutional amendment would have been likely to survive a court willing to do what this one has done, and there is zero possibility the Democrats could have passed one.
Even Trump can occasionally be right!