"Mazel Tov" (מזל טוב) is a Hebrew phrase that literally means "good destiny" but is more commonly understood to mean "good luck" or "congratulations." "Tov" is the Hebrew word for "good" and "mazel" is the Hebrew word for destiny or constellation (as in the stars in the sky).
When is the appropriate time to say "mazel tov" to someone? Whenever something good has happened. Whether someone recently got married, had a child, became a Bar Mitzvah, or did well on an exam, "mazel tov" would be an appropriate (and very nice) thing to say.