Being "in" implies that you are within something, or inside of it. So if you say you live in Mexico City, that means you live somewhere in Mexico City.
Being "on" implies that you are on top of something or that you are using something. So if you say that you live on Mexico City, that means you are physically over Mexico City but not inside of it, which, of course, is impossible. You could say you are on a boat, or on an airplane.