How is a substance classified as a vitamin?
1) Vitamin D is a bit of an umbrella term that actually refers to a whole group of related molecules. One of these, vitamin D$_3$ (cholecalciferol) is formed spontaneously from ergosterol in the presence of UV radiation, which happens in the skin when exposed to sunlight. Cholecalciferol is then converted to calcitriol, the active form, in the liver. Here is some information on the metabolic pathway.

2) Actually, if you consider the definition carefully, only a few molecules are essential for human growth and nutrition, in the sense that they cannot be replaced with something else, and are required in small amounts. For example, the majority of amino acids can be synthesized by the body from other amino acids, and are therefore nonessential. The remaining amino acids are essential nutrients because there is no synthesis pathway -- but they are required in large amounts and not considered vitamins. This distinction between "large" and "small" might sound strange, but it is important since it tells you if the nutrient is consumed for energy/growth (like amino acids) or has some "supporting" role, such as antioxidants, cofactors for enzymes, or hormones (like the vitamins).

That said, it is sometimes a bit fuzzy if a nutrient is essential or not. Vitamin D is a borderline case: it should perhaps not be called a vitamin, since it can in fact be synthesized by most adults in adequate amounts. However, vitamin D deficiency can occur if one does not get enough exposure to sunlight, and this can cause the disease rickets. Some researchers have suggested that this is one factor behind evolution of lighter skin in northern human populations, since dark skin pigment reduces UV radiation needed for vitamin D synthesis.