The Argentine pontiff was speaking at the end of a solemn ceremony commemorating Christ's Crucifixion
Pope Francis has railed against the marginalization of convicts and others who society has deemed "sinners," and staunchly defended migrants as he joined hundreds of thousands of young Catholics in Panama.
In a swipe at US President Donald Trump's plans to build a border wall against Central American migrants, the pope on Friday told hundreds of thousands of young pilgrims that it was "senseless" to condemn every immigrant "as a threat to society."
The Argentine pontiff was speaking at the end of a solemn ceremony commemorating Christ's Crucifixion, which drew the largest crowd of pilgrims of his five-day visit.
The organizers said the Way of the Cross ceremony drew 400,000 pilgrims to hear the pope at a park in Panama City. The World Youth Day committee says 1,10,000 people had officially registered for the six-day event, which ends on Sunday.
The Vatican faced questions Friday over why the pope, who addressed hundreds of Central American bishops the day before, had not taken the opportunity to speak out against the scourge of clergy sex abuse afflicting the Church.
His spokesman Alessandro Gisotti said that it was never far from Francis' mind because the Church was under "incredible pressure."
But it was "not necessary" the pope should raise the issue at every gathering of bishops or of young people, he said.
Gisotti said next month's meeting of leading bishops in Rome would be a unique chance to provide them with "concrete measures" to tackle the "terrible plague."
In his evening homily, Francis returned to his theme of defending migrants during this visit to Central America, the hub for migrant caravans heading north through Mexico to the US border.
The Church wanted to foster a culture "that welcomes, protects, promotes and integrates, that does not stigmatize, much less indulge in a senseless and irresponsible condemnation of every immigrant as a threat to society."
The pope has previously spoken out against the "fears and suspicions" of migrants during his trip.
In the crowd was 23-year-old Honduran student Wiston Medina. "Many of my friends have lost their jobs and gone to the United States. Everyone in Honduras has family in the US, they left looking for a better future."
Plea for environment
In a wide-ranging speech at the end of the evening ceremony, the pope also made a plea for the environment that had been "trampled underfoot by disregard and a fury of consumption beyond all reason."
Society in general "has lost the ability to weep and to be moved by suffering."
Instead of solidarity "from an opulent society" many encountered rejection, sorrow and misery "and are singled out and treated as responsible for all society's ills."
Earlier, Francis broke away from the clamor of the global youth gathering to make a 40 kilometer road trip to a spare concrete youth penitentiary outside the capital.
For much of the journey, pilgrims and locals waved flags and cheered as he passed by.
"Where people's lives are concerned, it seems easier to post signs and labels," stigmatizing "not only people's past but also their present and future," he told the center's young inmates, many of whom are serving time for serious crimes.
"This attitude spoils everything, because it erects an invisible wall that makes people think that -- if we marginalize, separate and isolate others -- all our problems will magically be solved," Francis told them.
The pope listened closely to a young inmate identified as Luis, who shared his dream of becoming an internationally-renowned chef after he completes his sentence for an unspecified crime.
"There are no words to describe the freedom I feel at this moment," said Luis, in detention since 2016.
The Las Garzas detention center houses 192 young offenders and it was here that some 30 of them made the wooden confession boxes being used at the Garden of Forgiveness in Panama as part of the World Youth Day celebrations, which brought the pope to the country.
"The pope was visibly moved by his encounter as he listened to the words of this youth," Vatican spokesman Alessandro Gisotti told reporters later.
Singing Happy Birthday
The pope later heard the confessions of five of the inmates, including a young woman.
Afterwards, there were lighter moments when Francis approached a group of pilgrims who were waving banners and chanting outside the grim penitentiary fences.
He chatted with one elderly woman, and then told the crowd "This old lady, who is younger than I am, is doing well and today is her birthday, so let's sing to her!"
He then led the crowd in singing Happy Birthday.
In his speech, the pope said Jesus approached and engaged with sinners, "even putting his reputation at risk."
He told them they were not defined by the labels society had given them, as offenders.
"Keep fighting, all of you, to seek and find the paths of integration and transformation."