Inside President Donald Trump’s political team, the travel ban was something of a secret.

Even before Mr. Trump won the election, aides were working up a plan to make good on a campaign pledge to keep potential terrorists from slipping into the U.S.

They kept the circle tight as the work stretched from the campaign to the transition and then...