They are not mere folds in the skin. Scales, like fingernails, are the product of numerous dermal cells. These cells excrete a chemical compound which hardens into an extracellular matrix. Scales and fingernails are non-living structures which afford the animal sturdiness or protection. Scales and fingernails and hair are all stages in the evolution of such defensive excretions, which began long before any vertebrates existed.
Invertebrates form their hard secretions into shells.
The molecules which make up a shell or a fingernail are synthesized by one type of skin cell. Typical animal skin is composed of many cell types. Sometimes the excreting cells are dispersed throughout the other types of cells, across the full surface of the skin. In other cases, these cells are concentrated into lines or spots within the skin. The follicle of a feather is an extreme example of the secretory cells becoming concentrated into a spot.