In natural selection, organisms that are better adapted to their environment are more likely to survive and reproduce. This means that organisms that have traits that help them to survive in their environment are more likely to pass those traits on to their offspring.
Sacrificial bacteria have a trait that helps them to survive in their environment: they are able to produce a substance that kills other bacteria. This substance can help to protect the sacrificial bacteria from being killed by other bacteria.
However, the sacrificial bacteria also pay a price for this trait: they are often killed by the substance that they produce. This is why they are called "sacrificial" bacteria.
So, sacrificial bacteria are not altruistic or just unlucky. They are simply organisms that are following the rules of natural selection.