From Sweat to Sustenance
The mammary gland didn't appear from nothing. It evolved from modified apocrine skin glands — essentially, specialized sweat glands. Our synapsid ancestors (the lineage that would eventually become mammals) developed glandular skin secretions to keep their parchment-shelled eggs moist.
These early secretions contained antimicrobial compounds that protected eggs from bacterial and fungal infections. Over millions of years, this protective function expanded: the secretions became increasingly nutritious, eventually capable of fully sustaining offspring.