Stars and to a lesser extent planets twinkle simply because we are seeing them through the many layers of the atmosphere of the earth.
These layers of different densities move around, bending or scattering sortie of the light.
The upshot is that all the rays of light that could reach your eyes from a star don’t necessarily come in together, but sometimes more, sometimes less, depending on the danciness of the atmosphere.
There are several types of variable stars, stars that truly vary in their light output or are periodically eclipsed by other bodies, but the variations usually take place over a longer period than a mere twinkle.
Planets are closer and brighter in terms of the amount of light that reaches us, so they vary less.