From the Super Mario Wiki
Donkey Kong series
Coconuts appear in the Donkey Kong series of games, where they are shot by Neckys and Mini-Neckys as attacks. Another type of coconuts is the Crystal Coconut. In Donkey Kong 64, Donkey Kong uses his Coconut Shooter that fires coconuts.
"Donkey Kong in: Banana Day 24"
Coconuts also played a role in the Donkey Kong comic "Banana Day 24," published in the German magazine Club Nintendo. In this story, giant aliens connected Earth to their spaceship, pulling the planet away. As it turns out, they erroneously took Earth for a huge coconut, a fruit their species adores. They agree to return the planet back to its original position as Diddy Kong starts to give them Bananas in return.
Paper Mario series
Coconuts appeared in the games Paper Mario and Paper Mario: The Thousand-Year Door. These items are found only in Coconut Trees on Lavalava Island and Keelhaul Key. To get them from the trees, Mario can simply whack them with his current Hammer. Coconuts are used in many recipes. In Paper Mario, its use is as a weapon; it can be thrown at a single enemy to deal 3 HP damage. In Paper Mario: The Thousand-Year Door, it can be eaten by Mario or his partner to recover 5 HP instead. In the same game, Mario must give one to Flavio on Keelhaul Key to obtain a Chuckola Cola, which must be given to Admiral Bobbery. Coconuts are also mentioned in the Paper mario tattle for Stone Chomps.
Super Mario series
Super Mario Sunshine
Coconuts also appeared with various other fruit in Super Mario Sunshine at Delfino Plaza. Sometimes, it must be used as bait for a Yoshi to venture out of its egg. If a Yoshi eats one, it will turn pink and refill its juice. It can also be thrown by Mario. There are also tasks in the game if the player puts enough of them in a basket (or other fruits) that the player will be rewarded with a Blue Coin or 1-Up Mushroom. Unlike all over incarnations of the fruit in the Mario Franchise, the ones in this game are the correct color (coconuts are ripe green then dyed brown).
Super Mario Galaxy
Coconuts also appear in Super Mario Galaxy. Mario can spin into them to send them flying. This is useful for defeating enemies such as Pokeys. They are also used by King Kaliente as projectiles. When 9999 Star Bits are collected, all coconuts become watermelons.
Super Mario Galaxy 2
Coconuts reappeared in Super Mario Galaxy 2 from the previous Super Mario Galaxy game. Like its predecessor, coconuts are used to defeat Octopuses, Prince Pikante, open chests, etc. The way for making all coconuts become watermelons was also the same, by collecting 9999 Star Bits.
Paper Mario recipes
Names in other languages