Why is the number of mg of medication different in different allergy pills?

Different medication. The mg. Amount of a drug will vary amongst the different classes of drugs because they are different compounds. Fexofenadine typically is a 180 mg dose, where loratidine is 10 mg. They are "equivalent" because in studies they block about the same number of histamine receptors and provide equal efficacy.
Different compounds. Each medication has a different molecule which is the active compound. These compounds can vary in size and weight, as well as effectiveness. Medical studies are required to determine how much of each compound is needed to create the desired effect in the body while not causing undesired side-effects. Since each compound is different, the milligrams (weight) will vary.