When is total parenteral nutrition necessary?

Necessary... Total parenteral nutrition, tpn, is needed when the gut is not functional for any reason. There are many scenarios when it becomes necessary including post-op from a surgery on the intestines, massive trauma, infections causing massive vommiting, hyperemesis of pregnancy, etc.
No use GUT. when you are unable to absorb your food from your intestinal tract, then tpn is necessary. Examples might include after intestinal surgery of a large part of the small intestines. During cancer chemotherapy, the chemotherapy causes such severe damage to the intestinal tract, TPN might be indicated for ongoing nutritional support.