It is actually not an excess of calcium that’s usually the problem, calcium deficiency is actually a greater risk for most. While yes, the most common types are both chemicals that are in part calcium, the body is meant to produce them, just in different parts of the body. Usually, a deficiency in calcium allows those other compounds that should be used up in other places to be flushed through the kidneys, possibly building up. Then incidental calcium that does move through the kidney binds to them there. Higher dietary calcium intake is associated with a sharp decline in stone risk, though extremely high intakes from vitamin supplements etc do increase risk. But in general, it is an excess of the things that bind to calcium that are the things to avoid, apparently almonds are pretty much the worse thing ever, with a fairly distant second being chocolate.
Dietary calcium is great for preventing stones, actually. Calcium is bound to a couple different things that cause stones, but the body actually makes those things specifically to bind with calcium. When it happens where it is supposed to, this is a good thing. If you are low on calcium, these things get flushed, and may get trapped in the kidney. Then any calcium that passes through may bind to it. Having higher calcium intake helps prevent them from building up in the kidneys to begin with. Though extremely high amounts of calcium from vitamin supplements etc can increase the risk of getting stones, but high calcium diet is one of the best defenses against them.