Chances are you've never felt threatened that your mom might just gobble you up one day - at least not in the literal sense of the word. But if you're a hamster baby, piglet, snake offspring, fish baby, insect toddler, or even primate kiddie, you should watch your back. Eating one's young may seem like the exact 180 of a good survival gene, but the fact that such cannibalism is seen throughout the animal kingdom means it must have some sort of sense, at least biologically speaking!
And in fact it does. This technique can act as a "crop control" method that lowers the number of offspring that a mother who gives birth to a large litter must take care of. A hamster mom isn't about to eat all of her babies, because that would leave her several steps backward in the gene-passing life goal. But eliminating several offspring (usually two out of a litter of eight) allows her to concentrate more resources into the other babies, giving them a higher chance of survival. And by eating them, she too gains important nutrients that can be passed onto her alive children.
Other animals use this method for different reasons. For example, the male sand guppy occasionally eats his "slow-poke" young - aka the eggs that don't hatch on time with the others. He can't be held up waiting to mate again with a new female just because five of his five hundred eggs are lagging, so down the hatch they go. And the long-tailed sun skink may eat her eggs when it is inevitable that they are about to be eaten by a predator; after all, she might as well receive that energy instead of her rival because it will help her prepare for a new round of reproduction. So as backwards as it seems, these animals know what they're doing when they down their babies as an afternoon snack.