Beryllium carbide formation
Briefly, it's a matter of cationic radii values and crystal packing at given $p, T$. Without referring to the detailed review of the corresponding crystal structures, you can imagine $\ce{M^{II}2C}$ as the derivative of methane $\ce{CH4}$, whereas $\ce{M^{II}C2}$ can be seen as the derivative of acetylene $\ce{C2H2}$. Smaller cation is the best fit for the "richer" tetrahedral coordination environment of carbon, whereas larger cation of the same charge won't be able to do so (sterical hindrance). That's why $\ce{Be2C}$ is the primary carbide of beryllium, $\ce{Mg2C}$ is also known to exist at higher pressures, (magnesium, along with lithium, otherwise forms an allene-based $\ce{Mg2C3}$ or $\ce{Li4C3}$ 2), but bulkier cations $\ce{Ca^2+, Sr^2+, Ba^2+}$ only form 1/2-carbides. Aluminium, on the other hand, forms $\ce{Al4C3}$ that hydrolyses to methane. This is a good example of the diagonal relationship between $\ce{Be}$ and $\ce{Al}$, and also between $\ce{Li}$ and $\ce{Mg}$.