Yeah, courts are subject to popular opinion in a way. I suspect many gay couples wanted to get married, but were denied in lower courts and appeals denied after. It's finally reached the popular critical mass to make it to the Federal level and that's why it's suddenly an issue.
But more importantly, when you actually read the arguments put forward in the cases, it takes the courts a very big legal stretch to side with the non-gay-marriage arguments, as they're almost uniformly non-legal and unconstitutional religious and traditionalist arguments.
This is actually completely backwards. It only became tenable to approach as a legal issue after gay marriage had become culturally acceptable.