It is because magnesium has a different metallic structures from the other elements in the group:
>beryllium and magnesium have a hexagonal close-packed structure
>calcium and strontium have a face-centred cubic structure and
>barium has a body-centred cubic structure.