The Homeland Security Digital Library has a Congressional Research Service note on the legal justification for quarantines:
Generally, state and local quarantines are authorized through public health orders, though some states may require a court order before an individual is detained. The Supreme Court has indicated that at least where Congress has not taken action, it is ‘well settled’ that states may impose quarantines to prevent the spread of disease. Nevertheless, the federal government has jurisdiction over interstate and foreign quarantines.
This says nothing about whether they are effective or good public policy.