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 a caveman, however, 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 with the @ glyph 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 a dog is also frowned upon and will convey intrinsic aggravate monster, but no luck penalty, if you are not an orc or caveman. However, there is no taboo on eating horses or any other former 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. Contracting lycanthropy will further extend the cannibalism restriction to beasts similar to your wereform even when you're still in your original form, but not to lycanthropes of your type.
Whether you are exempt from cannibalism rules altogether depends solely on 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. Furthermore, polymorphing into a mind flayer and eating brains may be considered cannibalism. Digestion attacks, e.g. as a purple worm, are not considered cannibalism.
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.