When the Patient Protection and Affordable Care Act was signed into law on March 23, 2010, President Obama's signature achievement was immediately confronted with (mostlyRepublican) opposition. Twenty-six states sued, alleging the law was not constitutional. After the issue made its way through the lower tier courts the Supreme Court finally issued a ruling on the matter on June 28, 2012. In a five to four ruling Obamacare was deemed to be constitutional. The individual mandate requiring everyone to purchase health insurance was at the heart of the issue.
Since five out of the nine justices are conservative (that is, Republican), supporters of Obamacare were understandably very concerned that the Patient Protection and Affordable Care Act would be ruled unconstitutional. For the uninitiated, Democrats are generally in favor of this law and Republicans are even more generally opposed to it. In order for the Supreme Court to uphold this law, one conservative justice would have to break ranks, assuming of course that all liberal (Democratic) members of the court also upheld the law.
In this case (conservative) Chief Justice John Roberts provided the swing vote necessary to uphold Obamacare. Why did he do it? Decisions made by judges should not be influenced by politics. Party affiliations are supposed to be irrelevant. Of course, in practice this is not the case. But with the Supreme Court thing are a little different. Justices are appointed to the Supreme Court for life so that they do not need to be concerned with elections. In other words, the members of the Supreme Court are not worried that unpopular rulings will cause them to lose their position on the bench. John Roberts was therefore free to do what he felt was legally correct.
It's a huge deal for a law to be ruled unconstitutional by the Supreme Court. The justices are legally required to search for some type of justification to uphold any law before it is struck down, as was correctly pointed out by Chief Justice Roberts. It was decided that the government can not force anybody to purchase anything, but that the individual mandate could reasonably be viewed as a tax. The government can (and does) impose many taxes. One way to look at it would be to say that everyone must pay this tax, but that one would be exempt from the tax if they buy their own insurance. There would also be other exemptions for things such as low income and religious beliefs. Of course, because the individual mandate is now considered to be tax, it will be easier to repeal, requiring only a simple majority in the House of Representatives and Senate (along with a Republican president who will not veto the repeal). So if you like Obamacare, vote for Democratic candidates in the next election.