JOHN ROBERTS, the Chief Justice of the Supreme Court, has conservatives vexed. To many of them, Justice Roberts' dissent to the majority's decision legalising gay marriage today seems flatly inconsistent with his reasoning in the King v Burwell case, which saved Obamacare. "Under the Constitution", Justice Roberts wrote in his dissent in the gay marriage case, "judges have power to say what the law is, not what it should be". But didn't the court effectively rewrite the text of the Obamacare just two days ago when it ruled that insurance exchanges established by the federal government should be counted among those "established by the states"? "The inside of John Roberts's head must be a very interesting place," tweets John Podhoretz, editor of Commentary. "Kind of like the Civil War, only no Confederate flag". Mr Podhoretz vividly captures a common conservative view of Justice Roberts today.

It is easy to see why Justice Roberts's two opinions may seem at odds. He seems both willing and unwilling to have the court say what the law should be. But Justice Roberts is in fact totally consistent. A closer look at his opinions on Obamacare and gay marriage show them both to flow neatly from a reasonable and perfectly coherent conception of the division of powers.

In the majority decision in King v Burwell, authored by Justice Roberts, the court ruled that, taking into account the whole context and design of the Affordable Care Act, it is clear enough that the legislature intended to make those who purchase insurance policies from federally established health-insurance exchanges eligible for tax credits, despite the fact that the clear language of the ACA seems to restrict eligibility to those who buy policies on exchanges established by the states. To conservatives and libertarians who had hoped to see Obamacare overturned, it seems that the court's majority, with Justice Roberts in the lead, has taken it upon itself to rewrite a botched piece of legislation.

However, Justice Roberts, in King v Burwell, does not see the court as saying what the law should be, as a philosophical or moral matter. He sees the court saying what the law actually is, as a matter of textual interpretation. The problem with the text of the ACA is that it is ambiguous. The overall design and intention of the legislation seems to be inconsistent with some of its language. In cases like this, Justice Roberts's said, it is up to the court to resolve the ambiguity and determine once and for all the correct reading of the legislation. If you simply assume that the plaintiff's reading of Obamacare was the correct one, and that Congress really intended to restrict subsidies to state-based exchanges, it may seem that the court is rewriting the law. But Justice Roberts sees himself as playing a constrained umpiring role, settling a dispute over what the law says. His decision actually affirms Congress's policy-making supremacy over both the court and the executive branch.

What's interesting, and so far under-appreciated about Justice Roberts's decision in the Obamacare case, is that the court explicitly denies that the executive branch had the authority to resolve the ambiguities in the text of the ACA. Many commentators predicted that the case would be decided on a principle known as "Chevron deference", first articulated in Chevron USA v Natural Resources Defence Council, whereby the court defers to a federal agency's interpretation of the law, so long as it is reasonable. But some on the court, Justice Roberts included, don't much care for the Chevron principle. It weakens the power of judicial review, the court's authority "to say what the law is", as first set forth in Marbury v Madison, which Justice Roberts duly mentions in his ruling. Now, in cases of large "economic and political significance", the Chevron principle does not apply. The court had not fully embraced this limit on a federal agency's authority to interpret the meaning of legislation until now, in the Obamacare decision. Although the court happens to agree with the IRS's interpretation of the statute, Justice Roberts' ruling goes to some pains to say that, because the IRS had not been specifically empowered by the legislature to make this sort of economically and politically significant determination, it did not have the authority to do so. The court need not defer to an authority the IRS—and indeed the executive branch as a whole—doesn't have.

This is a very important development. The court has ruled that when the interpretation of ambiguous legislation has potentially profound consequences, and Congress didn't delegate interpretative authority to a specific administrative agency, it is the court's job to decide what the law says. "It is...the Court's task", Justice Roberts wrote, "to determine the correct reading" of an unclear law. Which is a nice way of telling the executive branch to take Chevron deference and stuff it.

Cass Sunstein, a Harvard law professor, calls Justice Roberts opinion "a masterwork of indirection". Mr Sunstein, who had a hand in the executive branch's interpretation of Obamacare as the former head of the White House Office of Information and Regulatory Affairs, says that although the decision may vindicate the president's pet programme, "it is also a strong assertion of the court's, and not the executive branch's, ultimate power to say what the law is".

R.J. Lehmann, a senior fellow at R Street, a free-market think tank, sees a big upside to Justice Roberts's Obamacare ruling. "Roberts has just opened a huge new avenue for challenges to administrative rulemaking," Mr Lehmann writes. "From labour laws to environmental standards—not to mention reams and reams of tax rulings—there’s no shortage of federal rules" now open to challenge. Indeed, conservatives and libertarians may soon happily come to rely on the Obamacare ruling in their quest to rein in an unruly executive bureaucracy. They may find themselves embracing the division of powers Justice Roberts has so cagily persuaded the court's liberals to sign on to. Congress legislates. The executive gets to decide what ambiguous legislation means only if the decision doesn't have important economic or political consequences, or if Congress has granted that authority. Otherwise, it is up the court to settle what the law says.

In this light, Justice Roberts's dissent on gay marriage makes perfect sense. His complaint, in a nutshell, is that the court's majority, in finding an equal right to marry implicit in the constitution, has usurped the legislative function. Justice Roberts admits that the moral and practical case for same-sex marriage has "undeniable appeal", which has indeed swayed the legislatures in a number of states into legalising gay marriage. "But this Court is not a legislature," Justice Roberts writes. "Whether same-sex marriage is a good idea should be of no concern to us. Under the Constitution, judges have power to say what the law is, not what it should be". That is to say, the court has the power to interpret legislation, as in the Obamacare case, and to say whether or not legislation is consistent with the constitution. According to Justice Roberts, because "the Constitution does not enact any one theory of marriage", it remains up the states to decide what marriage means. When the court divines an equal right to marry, despite contradicting legislation in many states, "It seizes for itself a question the Constitution leaves to the people, at a time when the people are engaged in a vibrant debate on that question."

I would argue that Justice Roberts's two big rulings this week are not only logically consistent, but also right. In the Obamacare case, Justice Roberts, leading the majority, exercised the court's legitimate authority to interpret legislation, while putting the Obama administration on notice that it does not have the authority to make potentially profound judgment calls, even if they happen to be correct. In so doing, he helped save what is, in my opinion, a very bad piece of legislation, while cleverly opening a new route for beating back bureaucracy. In his dissent to the court majority's decision on gay marriage, Justice Roberts argued that the court has stretched its interpretative authority much too far, and has, in effect, written a brand new law. It may be the case, as I believe, that it is a very, very good law. However, one may be gleeful about the result while suspecting that Justice Roberts's is nevertheless correct: this isn't how it ought to have been decided.