Context: Within the core accretion scenario of planetary formation, most simulations performed so far always assume the accreting envelope to have a solar composition. From the study of meteorite showers on Earth and numerical simulations, we know that planetesimals must undergo thermal ablation and disruption when crossing a protoplanetary envelope. Thus, once the protoplanet has acquired an atmosphere, not all planetesimals reach the core intact, i.e. the primordial envelope (mainly H and He) gets enriched in volatiles and silicates from the planetesimals. This change of envelope composition during the formation can have a significant effect on the final atmospheric composition and on the formation timescale of giant planets.

Aims: We investigate the physical implications of considering the envelope enrichment of protoplanets due to the disruption of icy planetesimals during their way to the core. Particular focus is placed on the effect on the critical core mass for envelopes where condensation of water can occur.

Methods: Internal structure models are numerically solved with the implementation of updated opacities for all ranges of metallicities and the software Chemical Equilibrium with Applications to compute the equation of state. This package computes the chemical equilibrium for an arbitrary mixture of gases and allows the condensation of some species, including water. This means that the latent heat of phase transitions is consistently incorporated in the total energy budget.

Results: The critical core mass is found to decrease significantly when an enriched envelope composition is considered in the internal structure equations. A particularly strong reduction of the critical core mass is obtained for planets whose envelope metallicity is larger than $Z \approx 0.45$ when the outer boundary conditions are suitable for condensation of water to occur in the top layers of the atmosphere. We show that this effect is qualitatively preserved even when the atmosphere is out of chemical equilibrium.

Conclusions: Our results indicate that the effect of water condensation in the envelope of protoplanets can severely affect the critical core mass, and should be considered in future studies.