The Equal Protection Clause. Trump's EO on the ban included legal residents, not just non-citizen, non-residents. The Constitution absolutely applies to legal residents. 

If Trump's EO had only applied to non-residents - those without a visa, and didn't appear religion-based, then he'd absolutely have a legal right to ban the entry of persons from certain countries that pose a threat.