Mother hamsters do eat their newborn babies sometimes if resources and space are low, if there are sick or too many babies in the litter, if the babies smell foreign or if the mother is stressed.
At the end of the day its survival of the fittest, resource management and trying to keep your sanity.
Tbh, hamsters are weird in general.