Cannibalism is eating a monster of your own race. Generally speaking, this is a bad idea: you will gain the aggravate monster intrinsic and lose 2-5 points of Luck. If you are an orc or caveman though, cannibalism is considered natural for you and you will not be penalised.
If you are a dwarf, an elf, or a gnome, it should be clear which monsters are your own race, but if you are a human, it can be harder to tell. Anything represented by an @ sign that isn't obviously an elf is human. That includes werecreatures and doppelgangers but not Medusa, who should not be eaten for a different reason. Keystone Kops (anything represented by a K) also count as humans. Beware: a human character should not use blessed tins of nurse meat except in emergencies!
Eating a cat or dog is also frowned upon and will give you aggravate monster (but no luck penalty) unless you are an orc or caveman. However, there is no taboo on eating horses or any other monster that was once your pet. (This is different from the rules for sacrificing where you may not sacrifice your own pet but may sacrifice a wild cat or dog.)
As of NetHack 3.6.0, polymorphing into another form extends the cannibalism restriction to the new form, plus that of your base form. Orcish heroes and cavemen will never be affected by cannibalism, but a human polymorphing into an orc could not safely eat orc or human corpses. Additionally, polymorphing into a mind flayer and eating brains can be considered cannibalism. Digestion attacks, e.g. as a purple worm, are safe.
In SLASH'EM, a human eating a gibberlings is considered cannibalism. Vampires are immune to cannibalism, like orcs. SLASH'EM additionally does not contain the polymorph restrictions, and only explicitly eating the corpse of your base race is considered cannibalism.