They aren’t.
In fact, quite often on a lot of magazines, if you measure the lips, 9mm and .40 are identical. Sometimes the follower is different, though.
During the 94AWB, a “work around” the 10rd mag cap was to use a .40 magazine in your 9mm; you could usually fit 12-14 rounds of 9 in a ten...