The judges rejected an argument by the Trump Administration that the order was done in the name of national security, saying the record shows Mr. Trump belatedly consulted agencies that deal with that matter, and only after his first travel order had been derailed in the courts.
Trump has previously vowed to fight the case to the end.
Trump issued his initial travel ban by executive order in January, but that measure - which banned entry to nationals from seven countries for 90 days and suspended the nation's refugee program for 120 days - was quickly halted by the courts. Due to a time lag in the amended order, the second ban was never implemented as it was blocked just hours before it was due to come into effect.
A key issue now is whether those comments from the campaign can be used to show that the ban was unconstitutionally targeting Muslims due to their religion. President Trump rewrote the entry ban after the 9th Circuit in February refused to lift an earlier injunction.
The American Civil Liberties Union, which led the legal challenge against the travel ban, celebrated the win on Twitter. From its pro bono representation of refugees seeking asylum in this country, Human Rights First has witnessed the devastating impact implementation of this executive order would have on people from their targeted countries.
Gregory also noted in the majority opinion that there was a limit to the president's power to restrict people from entering the United States.
"The evidence in the record, viewed from the standpoint of the reasonable observer, creates a compelling case that EO-2's [Executive Order Two] primary goal is religious".
President Donald Trump suffered another defeat in trying to put a ban in place for certain nations to be able to travel to the United States of America.
Chief Judge Gregory, who wrote the majority opinion, was first installed in a recess appointment by Democratic President Bill Clinton and then nominated to the same post by Republican former president George W. Bush. "Because of their nature, campaign statements are unbounded resources by which to find intent of various kinds", Niemeyer wrote.
During two hours of argument before the appeals court May 8, the American Civil Liberties Union argued that the order had a religious objective that violated the establishment clause in the First Amendment of the Constitution, which bars establishment of religion, and that the president is not allowed to set a policy that violates the establishment clause by invoking national security.
Trump will likely appeal to the U.S. Supreme Court.
The Richmond court's 10 to 3 decision said the president's immigration power is not total. The Fourth Circuit concludes that the plaintiffs in this case would very likely succeed in their argument that the ban violates the Establishment Clause. In rulings striking down voluntary student prayers at football games, a minute of meditation or voluntary prayer at the beginning of the school day, and a law requiring that creationism be taught alongside evolution, Niemeyer said, the high court found the government actions "inexplicable but for a religious objective".
"The president can not simply slap the words "national security" on an unconstitutional policy and get away with it".