Does the Supreme Court simply rubberstamp the prevailing social
consensus?
No.
Structurally, The Supreme Court Is Designed To Lag Behind Social Consensus
U.S. Supreme Court justices are political appointees with discretion over how laws are interpreted and enforced in the U.S. that cannot be reviewed by any other body, in the case of constitutional law, and can only be second guess by Congress and the President acting together, in the case of statutory law.
Since U.S. Supreme Court justices serve for life, they tend to be lagging indicators of the political preferences of past Presidents.
Plessy v. Ferguson was influenced by post-Reconstruction judicial appointments trying to salvage what it could from the end of the slavery regime for former slave states, although Congress could have overruled it with new legislation if Senators from Southern states hadn't filibustered that kind of legislation in the U.S. Senate.
Still, while the law changes slowly, and the U.S. Supreme Court is often a lagging indicator of the prevailing social consensus, it is not frozen in time either, both because legal norms change over time, however slowly, because statutes and constitutional amendments change the environment in which the U.S. Supreme Court operates, and because sometimes the law commands them to do so.
For example, in 8th Amendment jurisprudence (the prohibition against cruel and unusual punishments), the "unusual" part of "cruel and unusual" has always incorporated prevailing social consensus, by design and by virtue of the express constitutional text.
Precedent Still Matter
Precedents also matter, however. U.S. Supreme Court Justices, while they may be influenced by a political ideology that had a lot to do with why they were nominated in the first place, are not simply legislators in robes.
While the U.S. Supreme Court is well known for its partisan split votes on close political issues, there are many areas of law where the U.S. Supreme Court is still far less partisan than elected officials, and often, split decisions in the U.S. Supreme Court on less politically charged issues are not along partisan lines. U.S. Supreme Court Justices cross partisan lines far more often than elected officials do, and the amount of partisan line crossing that takes place in courts below the Supreme Court that have a legal duty to follow the precedents of courts superior to them is even greater.
At the time of Dred Scott and until the 13th Amendment was passed in the wake of the U.S. Civil War, slavery was legal and its legality had never been seriously doubted in U.S. legal precedents. Precedents at the time, including a series of highly sensitive legislative and constitutional compromises already agreed to by other parts of the government, supported this ruling, whether or not it was good policy.
Obergefell v. Hodges, followed a nearly unanimous groundswell of support for the position that the U.S. Supreme Court ultimately took from state courts and lower federal courts, applying a variety of precedents already in place going back to Griswold v. Connecticut, 381 U.S. 479 (1965), which affirmed that the fundamental rights found in the Fourteenth Amendment's Due Process Clause "extend to certain personal choices central to individual dignity and autonomy, including intimate choices that define personal identity and beliefs," but the "identification and protection" of these fundamental rights "has not been reduced to any formula," and Loving v. Virginia, 388 U.S. 1 (1967), invalidating laws prohibiting interracial marriage. The lesser known cases of Zablocki v. Redhail, 434 U.S. 374 (1978) (invalidating a Wisconsin law limiting the right of non-custodial parents to remarry), and Turner v. Safley, 482 U.S. 78 (1987) (allowing prison inmates to marry without state permission) had also established a constitutional right to marry. In Romer v. Evans, 517 U.S. 620 (1996), the Supreme Court struck down a Colorado law that barred local governments from protecting gay rights. In 2003, the Supreme Court in Lawrence v. Texas struck down Texas’ sodomy law - and in turn invalidated sodomy laws in 13 other states - making private, consensual, adult sexual activity between same-sex couples legal across the U.S. In United States v. Windsor (2013), the Supreme Court held that a same sex couple legally married in Canada could not be denied the federal estate tax spousal deduction invalidating Section 3 of the Defense of Marriage Act as unconstitutional. The same day, in Hollingsworth v. Perry (2013), the Supreme Court held that California Proposition 8 (note that a majority of voters in this very liberal state passed this measure in 2012 suggesting that allowing same sex marriage was not the prevailing social consensus) which prohibited California from recognizing same sex marriages lawfully entered into after a couple prevailed in a 2009 court fight to secure same sex marriage rights under prior California law was unconstitutional. In 2015, SCOTUS responded not to a public opinion social consensus, but to a legal consensus among U.S. appellate judges driven by its own precedents.
Many states in which judges struck down same sex marriage bans before the U.S. Supreme Court took up the issue did so in states where same sex marriage was not popular, because fifty years of accumulated precedents from 1965 to the present strongly pointed in that direction. As a result, on the eve of the Obergefell decision, 37 states and the District of Columbia already recognized same-sex marriage, and only 13 states had bans. Those bans were mostly struck down as a result of lower courts interpreting existing U.S. Supreme Court precedents like the ones mentioned above, and as a result of legislators seeing the writing on the wall and wanting to take credit for the inevitable.
The act of nationalizing the right to same-sex marriage also reflected the reality that even though the constitution allocated regulation of marriage to the states rather than the federal government, as a general matter, that allowing a particular couple's marriage to be recognized in some U.S. states and not others, was basically unworkable in a country with freedom of travel between states.
SCOTUS Often Establishes The Prevailing Social Consensus
Also, while sometimes the U.S. Supreme Court does give official recognition to the prevailing social consensus (which is closely related to what becomes law by one means or another anyway), perhaps more often, a U.S. Supreme Court ruling establishes and changes the prevailing social consensus.
Support for interracial marriage in opinion polls, which wasn't terribly high when Loving v. Virginia was decided in 1967, soared after the U.S. Supreme Court declared it to be a matter of constitutional law.
A question from a 1968 international Gallup poll underscores the
extent of U.S. opposition to interracial marriage during this period.
This question, which asked Americans and those in 12 other nations
whether they personally approved or disapproved of marriage between
whites and nonwhites, found even broader U.S. opposition than the 1965
question.
More than seven in 10 Americans (72%) disapproved of white-nonwhite
marriages, in contrast with only 21% of residents in Sweden, 23% in
the Netherlands, 25% in France, 34% in Finland, 35% in Switzerland and
36% in Greece. Opposition outweighed support in Austria, Canada, West
Germany, Norway, Uruguay and Great Britain, but to a far lesser extent
than in the U.S. The 1965 and 1968 U.S. reactions to interracial
marriage appear contradictory, but this is because each question
measures a different dimension of public opinion. The 1965 question
asks for people's views on the legality of interracial marriage --
whether it should be a crime -- whereas the 1968 question merely asks
Americans whether they personally approve.
Americans' personal views on interracial marriage eventually changed,
but it took decades for majority support to emerge. In 1978, more than
a decade after the Loving case, only 36% of Americans approved, while
54% still disapproved. Not until the 1990s did public approval cross
the 50% threshold, registering 64% in 1997. Gallup's latest update, in
2013, shows 87% approving.
(Source)
Support for same sex marriage has followed a similar pattern after Obergefell v. Hodges was decided.
Roe v. Wade (creating a constitutional right to medical abortion) and Griswold before it (creating a constitutional right to contraception and clearly establishing the concept of substantive due process rights to privacy), likewise dramatically changed public opinion on these issues.
So, while the U.S. Supreme Court is sometimes a lagging indicator of a social consensus that is already prevailing, its moral authority and the inability of any other political actors to overcome the legal force of its rulings has also caused it to be a major driver of social consensus going forward.
For example, until Brown v. Board of Education (1954), Plessy v. Ferguson was widely accepted as a legally fair standard and the support really only entirely collapsed when the U.S. Supreme Court said otherwise. Indeed, Brown v. Board of Education probably was pivotal in shifting public opinion in a manner that led to the adoption of the Civil Rights Acts of 1964 that finally put teeth into the political resolve to end racial discrimination that had begun in earnest in the Reconstruction era.