In the 18th century, Lima outnumbered Philly by a huge margin. Was it because of a headstart? Trade?
I'm not sure this counts as a comprehensive answer to your question, but part of the reason could probably be traced to the Spanish policy of reducciones. During the early 16th century, the Spanish colonial government found it difficult to maintain control over largely dispersed indigenous populations in rural areas. In Peru, this changed in the 1570s under the viceroyalty of Francisco Toledo. Part of the so-called "Toledo Reforms" involved forcibly relocating indigenous people to congregated urban centers like Lima in order to more efficiently manage them for labor requirements. This created a rapid period of urban growth in the Andes, as previously small settlements were abandoned and people were moved into larger urban centers.
In addition to this, Lima experienced more standard population growth associated with being both a regional capital and a center of trade. Spain's model of colonialism was primarily one of resource extraction, and given the rugged geography of western South America the most effective means of moving goods was by sea. Lima functioned as the main port for all goods moving to and from the Andes, and was also the seat of the colonial government, which made it a popular city for settlers.
And finally, Lima was founded in the mid-16th century, while Philadelphia was founded in the late 17th century. So it also had simply been around longer.