Corks pop out because of bottling wine too early and it is continuing to ferment in the bottle. As the yeast consumes the sugar still in the wine, it produces both alcohol and carbon dioxide (CO2) gas. In your carboy, the CO2 escapes through the airlock as bubbles.
Once you bottle the wine there is no place for the gas to go. Some of it is absorbed into the wine and the wine changes from a still wine into a sparkling wine. When the wine has absorbed all of the CO2 it can absorb and the pressure continues to build, either the cork is blown out of the bottle or the bottle explodes.
You should never bottle a wine that has not been stabilized or at least has a specific gravity lower than 1.000 and shows no sign of refermentation for 30 days after racking.
Here are some tips to keep this from happening again:
When apparent fermentation has stopped, rack the wine into a clean, sanitized secondary and reattach the airlock. Look at the wine 24 hours later. If there is positive pressure in the secondary (you are seeing bubbles coming out of the airlock), the yeast is still working. Racking allows the wine to absorb oxygen and this extra shot of oxygen often rejuvenates a wine that previously seemed finished.
When the pressure inside a carboy appears to go negative (i.e. the liquid inside the airlock is being pushed toward the part of the airlock connected to the bung), check it daily for two weeks to see if it swings back to positive. When high pressure weather fronts pass through an area, the liquid in an airlock will tend to be pushed downward by the high pressure and it will appear that fermentation has finally ended when in fact it hasn’t. The only way to know for sure is to take a hydrometer reading.
When you are sure all fermentation has stopped, check the specific gravity of the wine. If it is not dry (1.000 or lower), repeat the procedures in step 1, above. If it is dry, crush one Campden tablet per gallon of wine (or use 1/4 level teaspoon of potassium metabisulfite per 5 gallons of wine -- do not exceed this amount) and dissolve it and 1/2 teaspoon potassium sorbate per gallon of wine of in a half-cup to full cup of the wine. Stir very well to ensure it is completely dissolved. Pour this into a clean, sanitized carboy and rack the wine into it. Reattach the airlock and wait 10-14 days minimum (Midwest recommends waiting a full month).
Then bottle your wine as you normally do.