Why it's the capital
Francisco Pizarro chose the site because it was close to a good coast for a port but far enough from it to be safer from pirates. In 1543 Lima became the capital of the Spanish Viceroyalty of Peru, and after independence it became the capital of the new republic.