First, a cumulonimbus is a cumulus cloud that produces precipitation, rain, snow, hail, or sleet.
Anvil refers to the shape of a blacksmith’s anvil, which is a wide surface on top of a thinner base. A blacksmith pounds hot metals on the top surface of an anvil.
The anvil shape forms on top of a cumulonimbus (or a cumulus) because a wide stable mass of cold air in the atmosphere prevents the cloud from growing further in its usual fashion.
Usually, the small cells of warmer air rising and condensing within the cloud form billows that heap on top of each other, but the cold mass on top acts as a ceiling. The condensation spreads outward below the ceiling instead of upward.