The eggplant was named for the wrong color. The first ones English speakers knew were white, and they looked like eggs.
The name was literal when it appeared. Wikipedia says eggplant was first used for white cultivars whose fruit resembles hens' eggs. Other names of the period made the same comparison: "garden eggs," recorded in 1811, and "vegetable egg," in use from 1797 to 1888. The dates for the word itself differ slightly. Wikipedia gives 1763 as the first record, while Merriam-Webster gives 1767. Either way, it is a 1760s word.
Today the fruit is usually dark purple. Merriam-Webster describes it as "typically blackish-purple or white," and lists eggplant as the name of a dark purple color. American English kept the egg name anyway, so the word now describes a shape and color most buyers rarely see.
British English went another way and uses aubergine, which has a much longer story. Arabic al-badinjan, "the eggplant," came from Persian badin-gan. Etymonline traces it further back to Sanskrit, while Wikipedia points ultimately to Dravidian languages as well as Sanskrit. The word became Catalan alberginera and then French aubergine, where the Arabic al- softened to au-. Etymonline records aubergine in English from 1775.
Portuguese had its own form, bringella. It gave brinjal in Indian English, recorded from the 17th century.
In Italy the plant is melanzana. Folk etymology reshaped that into mela insana, "mad apple." English versions such as "raging apple" are recorded from 1578.
The plant itself is old. It was probably domesticated more than once, in South Asia and in East Asia, and its earliest known mention is a Chinese text of 59 BCE.