The Court is correct here. You cannot ban 15% of Muslims entering into the U.S. and plausibly argue the ban is meant to protect Americans from Islamic terrorism. Logically, the judges asked why the other 85% of Muslims entering the U.S. weren't banned? And none of the countries selected for banning birthed the 9/11 hijackers. And none of the countries on the banned list have citizens who carried out terrorist attacks in the U.S.
I think a law school student could have won the case against the ban. 
Amatuer hour at the WH.