Nail polish is a pigment – the color – dissolved or suspended in a liquid – the solvent. It dries out when the solvent evaporates leaving the pigment behind.
When it’s in the bottle there’s not much of a surface for the solvent to evaporate from, because most of it is well under the surface. And if some does try to evaporate, it’s stopped by pressure building up from other solvent that already evaporated into the closed bottle, pushing down on it.
When you put it on your nail, there’s a thin film of liquid + pigment and it’s all exposed closely to the air, with nothing to stop it from evaporating, so the solvent does evaporate quickly leaving the pigment behind, and it’s dry.