How do thiazides reduce calcium excretion through urine? And how do loop diuretics increase the excretion of calcium through urine?

you're right. They do exactly what you said: thiazides reduce urinary calcium excretion and are good for stone formers; loop diuretics increase it and are good for people with hyperparathyroidism and hypercalcemia. The mechanism is complicated. Unless you're taking an exam, this is sufficient information.