Although the name suggests that a coconut is a nut, it is in fact botanically classified as a fruit. Specifically, it is a drupe, a kind of fruit that is characterized by a fleshy outer layer and the fact that it develops from the ovary wall of a flower. Some other examples of drupes include nectarines, pistachios, almonds, and mangoes. The evolutionary advantage for drupes is that their fleshy outer layers attract animals, ensuring that they will be widely distributed along with a little natural fertilizer in the form of animal dung. In fact, some drupes are specifically designed to go through the intestinal tracts of animals.
The outer layer of a coconut is known as the mesocarp. Those in the store are usually stripped of their mesocarps, but people who have a chance to see one in nature will see the thick fibers that cover the fruit. These fibers are known as coir, and they are used in rope making and textiles in some regions of the tropics. Coir fiber is very strong and durable, although it can also be a bit itchy.
The next layer is the endocarp, which is the hard hull of the fruit that most people see when they buy whole coconuts at market. The endocarp protects the tender fleshy endosperm, the meat of the fruit. People may also note several soft depressions, which are designed to allow the embryo to grow if the drupe is fertilized and allowed to mature.
People eat coconut meat because it is the only palatable part of the drupe. It is rich in fat and nutrition because the endosperm is designed to nourish the embryo as it matures, giving it a start in life until it gets large enough to start photosynthesizing and absorbing its own nutrients. The more mature one is, the firmer and denser the flesh will be; in young coconuts, the meat can be almost like a jelly in texture.
Coconuts are one of a number of foods that are misnamed, at least from the view of botanists. They were probably associated with nuts, rather than fruit, because of their meat, which is intensely rich and flavorful, much like the meat of a nut. In fact, the endosperm of drupes like peaches and nectarines is also very rich, but humans cannot eat it because it is too hard and because it contains compounds that can make people sick.