MEXICO CITY—Mexico’s government has started detaining migrants marching in a caravan toward the U.S.-Mexico border, marking a policy shift as President Andrés Manuel López Obrador faces rising pressure from the Trump administration to stem the flow of migrants seeking to enter the U.S.

Hundreds of Central American and Cuban asylum seekers have been detained in southern Mexico in recent days and sent to overcrowded immigration stations near the country’s border with Guatemala, authorities and migration advocates said.

On...