It depends on if you are passing through security in Miami. If you intend to just change gate (and if it is possible) and not go into the "American" side of the airport at all then you should not need a US visa. However, if you are required to pass through security then you will need a US visa.
However, depending on what country your passport is from, you may be entitled to a "visa waver" which allows you 3 months stay within the US.
Note: You will also require whatever permits are necessary for your visit to Mexico.