At PTY, stay airside—Tocumen is efficient with good dining, and city trips don’t fit short connections.
A 3-6 hour layover in Panama City is very feasible. The Metro Line 1 from near Tocumen Airport to the city center costs $0.35 and takes 30-40 minutes. Head to Casco Viejo (old city) - the walk from the nearest Metro stop is 15 minutes or $5 taxi. Walk the seafront and Plaza de la Independencia. One drink at a rooftop bar overlooking the modern skyline, and back. Allow 90 minutes for the return.
Six to ten hours opens up the full contrast of Panama City. Spend the morning in Casco Viejo: the cathedral, the Interoceanic Canal Museum (excellent overview of the Canal's history), and the seafront promenade with views back to the modern skyline. Walk or taxi to Ancon Hill (15 min from Casco) for 360-degree views. In the afternoon, take a taxi to the Miraflores Locks Visitor Center (15 min from downtown, $22 entry) to watch Panamax ships pass through the Canal in real time - genuinely impressive. Return to the airport 90 minutes before your flight.
With 10+ hours, Panama City rewards serious exploration. Biomuseo (Frank Gehry's only project in Latin America) tells the story of the biological land bridge with excellent design. The fish market at Mercado de Mariscos has fresh ceviche and cold beers by the harbor from early morning. The Causeway (Calzada de Amador) connecting three islands in the Bay is excellent for cycling - bike rental available at the entrance. The Amador Cruise Terminal end of the Causeway has views of both the city skyline and the Canal entrance. Casco Viejo is lively into the evenings with excellent restaurants and bars.