Starlight crosses layers of air whose temperature and density keep changing, so their refractive index keeps changing too.
This atmospheric refraction shifts the star's apparent position and brightness rapidly, and because a star is a point source, the flicker shows as twinkling.
Planets are extended sources whose variations average out, so they do not twinkle.