Was Panama owned by Mexico?

No. During colonial times, present-day Panama was part of the Viceroyalty of New Granada, which also included Colombia, Venezuela, Ecuador, Trinidad & Tobago and Guyana, as well as some parts of present-day Peru and Brazil.

The rest of Central America -- with the exception of Belize, known at the time as British Honduras -- was part of the Viceroyalty of the New Spain, which eventually became present-day Mexico, several U.S. States such as California and Texas, as well as Guatemala, El Salvador, Honduras, Costa Rica and Nicaragua.