Washington (CNN) Pope Francis on Sunday spoke out against governments that build walls to keep out migrants, reiterating his calls for a compassionate approach to migration.

"Those who build walls will become prisoners of the walls they put up," the Pope said. "This is history."

Francis made his comments to reporters while flying to Rome after a visit to Morocco, and when asked about the efforts of several nations, including the US and Spain, to build walls and fences to keep out migrants, Francis made his remark.

He said he wept after a Spanish journalist showed him a piece of concertina wire from the border of Spain's north African enclave of Ceuta, which borders Morocco.

Francis' remark about walls has particular resonance in the United States, where President Donald Trump has pledged to build a wall along the US-Mexico border and railed against undocumented immigrants.

Read More