Magnesium is lighter than Aluminum because it is in the 2nd group of the periodic system to the left of Aluminum residing in the 3rd. The latter has got one additional proton and a couple of neutrons more.
There’s more to it than their atomic weights. Magnesium (24 amu) is ~66% the density of aluminum (27 amu). As I understand it, the crystalline structure of aluminum is more “tightly packed” than that of magnesium.