The branch that studies the different structures at microscopic level is Histology and histopathology (in case you study tissue for abnormalities). In histopathology you apply different preparation and staining techniques and try to study the tissue under the microscope and figure out if the tissue is normal or has some abnormality in it or even study if the tissue belongs to the organ which was biopsied, that's how for example metastatic cancers are figured out.
The specialty in medicine that studies tissues is "Pathological anatomy" and the doctors who are specialized are called pathologists, it generally involves less interaction with patients but has a wide opportunity for research. Also a dermatologist (not all) could be well formed in skin histology and could observe skin biopsies and decide what tissues are found but generally the biopsies are sent to the pathologist, also a biologist could specialize in studying body tissues. There are also histotechnicians and Histotechnologists (more specialized than histotechnicians) who studied how different tissues are prepared for studying and how to apply sophisticated techniques of preparation for the biopsies for the pathologist to study them, they are an integral part of the laboratory. Generally the pathologist is the authority in the hospital on the characteristics of the biopsies (all tissues not only skin) and gives the final word.
As for toenail histology, you can differentiate completely a nail plate from the skin as it will be completely formed of cornified dead epidermal keratinocytes without the other layers of skin cells. (Cornified cells is found also on the outer layer of skin but it will be much less thick than the nail plate and the other normal skin layers will be found).
The nail bed is formed of skin cells but there are only 3 layers and lacks the other layers found in normal ski.
The matrix is also formed of a specific skin cells layers and lacks the granular layer normally found in the skin.
This article is very excellent in explaining the different characteristics of each constituent of the nails and how they differ from the normal skin.
https://www.actasdermo.org/en-nail-histopathology-articulo-S1578219013001443