The origin of coconut seems like it should be pretty straightforward. The spherical fruit with a thick husk of coir on the outside and a sweet edible liquid and meat on the inside comes from the coconut palm, also known as the coco. The coconut is the nut of a coco, though nut here uses the looser meaning of the term, as botanically it is considered a drupe. Coco is derived from Spanish and Portuguese words meaning “bogeyman,” “grimace,” or “coconut.”
Although the coconut is in no way related to the cocoa bean, we see the spelling cocoanut (or cocoa-nut) in occasional references from the past. You can find Cocoanut Avenue, for example, in Sarasota, Florida. The first full-length feature film starring the Marx Brothers, released in 1929 and based on a stage musical by George S. Kaufman, was called The Cocoanuts—it was set in a resort called the Hotel de Cocoanut in Florida. Cocoanut Grove was the title of a 1938 film starring Fred MacMurray, as well as the name of a Boston nightclub that was the scene of a notorious deadly fire in 1942. And there are examples using the spelling from literature:
The gust of wind struck the pandanus tree overhead and tore through the palms beyond, flinging half a dozen ripe cocoanuts with heavy thuds to the ground.
— Jack London, “The House of Mapuhi,” South Sea Tales, 1911Those alone who have tried it, know how delicious it is to be seated in such shade, and drink the cool pleasant fluid of the cocoa-nut.
— Charles Darwin, The Voyage of the Beagle, 1839
At PopSugar, Kate Schweitzer shares a citation given in a list of instructions given in 1968 by a hospital to mothers of newborns:
A particularly notable section of the instructions is an all-caps list of the banned foods for a new mom to eat, which include chocolate candy (how dare you!), apples, cabbage, nuts, strawberries, cherries, onions, and an oddly specific "green cocoanut cake."
— Kate Schweitzer, PopSugar, 9 Apr. 2019
The spelling cocoanut is rarely used in contemporary texts, the shift to coconut prompted possibly by a need to distinguish the word from an entirely different plant product, the cocoa nut.
The words “Cocoa” or “Koko,” etc., should never be used as an abbreviation for the name “Cocoanut,” as “Cocoa” describes an individual product of chocolate, and the word “Koko” implies same.
— V. L. Price, Confectioners' and Bakers' Gazette, Volume 36, 10 Jan. 1915
Cocoa nut is the obsolete name for the cacao nut, which itself is not technically a nut; it is, rather, the seed of the cacao tree. Cacao is the seed used in making cocoa; its name derives via Spanish from the Nahuatl cacahuatl.
It is usually pretty easy to judge from context whether a piece of writing that includes cocoanut or cocoa-nut is referring to the palm fruit or the cacao plant seed. But the use of puns such as “Coco-Nut” in brand names might lead to ambiguity about whether a product contains coconut, chocolate, nuts, or some combination of the three.