Wikipedia:
Fish scales are dermally derived, specifically in the mesoderm. This fact distinguishes them from reptile scales paleontologically.
So aren't reptilia scales also dermally derived?
No, fish scales are dermal (= formed in derma) bones like skull roof bones. Scales in reptiles are formed by epidermis and are made primarily of protein (from keratinocytes), being similar in derivation to hair, feather and nails.
On the other hand, in reptiles one must differentiate between scales and osteoderms (= scutes). Scutes are widespread among reptiles and they are similar to fish scales in that they are produced in derma and are ossified. Similar structures are found in some amphibians and in armadillo. Nevertheless, different types of osteoderms are currently considered as converges: "it is essential to recognize that osteoderms represent non-homologous structures that have been independently evolved a number of times" and have no direct homology with fish scales.
The scales of reptiles are made of proteins not present in fish, and are regulated by genes not present in fish.
Proteins produced in the skin prevent amniotes from drying out. A specific kind of springy protein (corneous beta protein) produced by sauropsids (lizards, crocs, birds, etc.) produces what we now look at and call scales. This protein makes tiny springy bits that are ~50% smaller than the smallest bits in keratin proteins that we mammals make, so it may be critical for allowing the evolution of fancy feathers. Sauropsida mix these springy proteins into their hard skin bits to control how flexible, strong, etc. the pieces are.
I find this recent review paper super-helpful: https://onlinelibrary.wiley.com/doi/epdf/10.1002/jez.b.22840
To summarize, the last common ancestor of a tuatara and a sparrow probably had some resistant skin material made with corneous beta proteins that formed in the upper layer of skin. Crown-groups evolved increasingly complex assignments for this material: claws, scales, shell, feathers, rhamphotheca.
I'm glad to see this review paper, because this makes the springy protein inside the scales of lizards and birds another good synapomorphy of sauropsids, which is easier for college freshman to see on the first week of class than the wacky regrown history of diapsid skulls.