Magnesium and beryllium are not really anomalous. Their poor solubility or nonsolubility in ammonia can be correlated with the fact that their ions are more densely charged than those of the alkali and heavier alkaline-earth metals that do readily give solvated electrons in liquid ammonia. However, at least for magnesium solvated-electron solutions can be formed in some other solvents or, in ammonia, with an electrolytic process.
Let's look more closely at magnesium, for which much more is known experimentally about solubility and solvated-electron generation than for beryllium. Compared with lithium, calcium and the elements below these, the greater charge density of the magnesium ion (and by extension, the beryllium ion) inhibits solvated electron formation in at least two ways.
The metal gets passivated. Solvated-electron solutions of metals in ammonia are not completely pure metal-ammonia solutions. The highly electropositive metals will slowly react to form the amide and hydrogen, but the amide ion in solution stabilizes the solvated electrons and thus also slows the reduction reaction. But with the doubly charged and compact magnesium ion, the hard-base amide ion form a salt with little solubility. This inhibits metal dissolution rather than stabilizing solvated electrons.
What does dissolve, reacts faster. With its compact size and double charge, magnesium ion polarizes the ammonia molecules and tends to displace protons. These then react (as solvated ammonium ions) with the solvated electrons.
IUPAC has published a review by Lagowski  which includes a discussion of metal solubilities in ammonia solvent. Magnesium is considered "soluble" in their table, but the text indicates that this is a borderline case and other solutes, such as ammono-bases, are needed to get a stable solvated-electron solution. Magnesium is shown with a higher ion charge density than any of the clearly soluble metals, including the lanthanides europium and ytterbium.
Thus compared with metals that form those blue solutions, magnesium dissolves more slowly and reacts faster, and so few solvated electrons can accumulate in a proposed magnesium/ammonia solution.
Magnesium is certainly electropositive enough to generate solvated electrons. Xu and Lerner  report that magnesium along with its heavier congeners calcium, strontium and barium generate solvated electrons in ethylenediamine, these electrons being captured by graphite to form blue or green intercalation compounds. (Curiously, magnesium and barium appear to adopt a +1 oxidation state while the intervening metals go to +2.) Significantly, magnesium requires more aggressive conditions of higher temperature and longer time to react, a difference the authors attribute to the effects of passivation (correlated with compact ion size) and compare with lithium versus other alkali metals.
More relevant to dissolution in ammonia is the electrolytic process described by Combellas et al. . In this process, the magnesium is dissolved electrolytically into a magnesium salt solution, generating reasonably stable solvated-electron solutions. Such solutions find use in reductive activation of PTFE surfaces without undesirable carbonization that alkali metals tend to produce; and since the process is electrolytic it can be controlled by way of the electric current. The electrolytic process breaks both barriers cited above. With the polarization the magnesium dissolves much faster than it would as an isolated metal, and observations of solvated electron lifetimes made by the authors indicate that the dissolved salt is stabilizing the blue solution against hydrogen evolution. (The authors do not give a solution-chemistry explanation for this, but the observations are consistent with the magnesium being incorporated into singly-charged ion pairs rather than remaining as independent +2 ions.)
J.J.Lagowski, "Solution Phenomena in Liquid Ammonia", http://publications.iupac.org/pac/25/2/0429/pdf/index.html.
W. Xu and M. M. Lerner, "A New and Facile Route Using Electride Solutions To Intercalate Alkaline Earth Ions into Graphite", Chemistry of Materials 2018 30 (19), 6930-6935. https://doi.com/10.1021/acs.chemmater.8b03421
C. Combellas, F. Kanoufi, A. Thiébault, "Solutions of solvated electrons in liquid ammonia: Part 1. Chemical properties of magnesium solutions", Journal of Electroanalytical Chemistry ,
2001 499, 1, Pages 144-151. ISSN 1572-6657, https://doi.com/10.1016/S0022-0728(00)00504-0