It is Constiutional for the government to require all hospitals that receive any federal funds to treat patients needing emergency aid.
The Constitution says Congress has the power to make all laws that are Necessary and Proper in carrying out it's duties.
The individual mandate is necessary in order to provide emergency aid to anyone in America.
The medicaid expansion is legal because it is a voluntary program that the states agreed to. They can theoretically leave at any time. Just because it is not politically feasible to do so is not a constitutional argument.
If the law is as unpopular as the polls say, then there's no reason the people won't elect people to change it or repeal it. That being so, judges should practice judicial restraint. It would be different if there was no political recourse.