customs and immigration – Panama (PTY) to Mexico (MEX) transit to Mexico (MEX) to Panama (PTY)

I recommend putting all your details into https://www.iatatravelcentre.com/passport-visa-health-travel-document-requirements.htm

It looks like you would need a Visa for Panama and a negative PCR Covid test taken at most 48 hours before arrival. Timing of this test may be tricky.

Mexico requires a Visa but you may qualify for TWOV (Transit Without Visa) if you transit in Mexico city with a layover of less than 24 hours and have proper documentation for your onward flight. Details around this are bit sketchy, so I would check with the airline.

.

buy a ticket from PTY to MEX (COPA) and then another ticket from MEX to PTY (COPA)

This makes no sense. Why do you want to fly from PTY to MEX and then back to PTY? Did you mean NAS->MEX->PTY? I couldn’t find anyone who currently flies from Nassau to Mexico, so that’s apparently not either.

However it looks like Copa has a non-stop NAS-PTY on 6/12, so maybe you can just go a day earlier