There is no real way to prevent deaths like this in hatchlings of any kind. You can have this happen with every species of egg layer. It just means something likely wasn’t right with its development, and natural selection took place because it wasn’t strong enough. Had it happen with chickens a couple times in the past. This happens more often than you would think, but yes it is technically bad luck.
I will add that sometimes you can save them by helping them once they pip, but it doesn’t always work. I will share my story with a chicken as an example. One chicken I had that pipped and was chirping like mad so I decided to help it after a bit. Started cracking the egg and the membrane was thick and leathery like a reptile egg. I carefully cut the egg after pinching a bit of it, tore it the rest of the way and was more than disturbed by what I saw. The baby had no abdomen or developed body, and all of it organs were held in by that membrane. It died a few seconds after I opened the egg.