ABOARD THE PAPAL PLANE — Pope Francis, putting President Trump on notice, warned on Sunday that those who close borders “will become prisoners of the walls that they build.”

The remarks came as the pope was returning from a visit to Morocco, where he worked to further his priorities of supporting migrants and establishing closer relations between the Roman Catholic Church and moderate Islam.

Mr. Trump threatened Friday to seal off the border with Mexico and moved to cut aid to Guatemala, Honduras and El Salvador to punish them for failing to stop a surge in migrant crossings into the United States.

Francis, who suggested in 2016 that Mr. Trump was “not Christian” for his belief in building walls, rather than bridges, was also asked aboard the papal airplane about the Spanish government’s efforts to keep out migrants, many of whom depart from Morocco.