In the broadest sense, your formulation spoiled because some sort of microbes overcame your preservation system and are now having a party in your project, devouring all the delicious ingredients and making themselves a lovely little homestead.
There are quite a few reasons this could happen, but here are some of the more common ones.
You don’t include a preservative.
If your product contains water and isn’t designed to be used immediately, it needs a broad spectrum preservative. It’s also recommended to include one in anhydrous products that could or will come into contact with water, like a shampoo bar that lives in the shower.
The preservative you used was not well-suited to the formulation.
Different preservatives have different strengths and weaknesses that need to be considered when formulating, and not all preservatives work well in all formulations. Research your preservative and make sure it is suitable.
The preservative you used wasn’t actually a preservative.
Vitamin E, sodium lactate, and rosemary seed extract are three examples of ingredients that are sometimes sold as preservatives but aren’t. If you used one of these ingredients instead of a preservative, that’s likely the problem.
Something happened to de-activate the preservative.
Different preservatives have different requirements for maximum temperatures, pH, and more. Make sure you have not over-heated your preservative (leaving something like Optiphen Plus, with its maximum temperature of 50°C, in a hot car in the summer could be problematic), and make sure the pH of your formulation is appropriate.
There was so much contamination in the product that your preservative was overwhelmed.
There are many potential sources of contamination, including poor manufacturing process, ingredients, and the end user. Try reducing these sources by ensuring you are following good manufacturing standards, your ingredients are sourced from reliable suppliers, and packaging your products in a way that reduces potential contamination by the user.
As always—know your ingredients. Preservatives and preservation are massive, complex topics, and it’s important that you understand how your preservative works and what it needs to succeed. Different preservatives have different strengths and weaknesses that need to be considered when formulating. Here are some helpful resources to get you started on your research: