Pass a law? Why would that have made any difference?
If it is a federal law, then it's harder to challenge and harder to overturn. That's the entire point.
To get a law overturned by the SC, you have to be able to effectively argue that the law itself is unconstitutional.
It's not that difficult to follow. Obergefell was an SC interpretation that said the federal government does not have a constitutional basis for denying same sex marriage. If that's all they did, it would remain at risk of challenge. But that's NOT all they did - congress passed an actual for realsies LAW that clearly states that same sex marriages are legal across the US. That makes it much, much harder for the Respect for Marriage Act to be overturned.
The same is true for ACA - there is no constitutional basis for health insurance, but there is an actual real law. BEcause it's a law, it has withstood tons of legal challenges, and I'm pretty sure it will withstand many more. Because to overturn it in part or in whole, the challenger has to be able to convince judges that it is
unconstitutional. That's how they got the mandate overturned - they deemed that it was unconstitutional to enact a tax in that way. But the remainder of it stays in place because it is not unconstitutional.
There's nothing in the constitution that forbids or otherwise prevents congress from making a law with respect to abortion.