Twinkling (astronomical scintillation, or just scintillation) is the changing appearance of stars observed from the surface of the Earth, which results from atmospheric conditions (i.e., seeing). In general, stars are seen to twinkle and planets are not. Effectively, portions of the atmosphere with differing indexes of refraction (generally due to air temperature differences), are moved around by air currents causing random changes, brief instances of some of the same types of issues with use of a lens. Color changes can result from "prism-like" effects. Brief blocking of the light by wisps of clouds or pollution can contribute to the general effect.
The kind of twinkling we see does appreciably not occur when viewing in space, e.g., astronauts, but conditions can occur in the interstellar medium, etc., to produce the same kind of refraction. Twinkling due to Earth atmosphere is reduced by a telescope's large aperture, by very clear conditions, probably by very dry air, and by circumstances that reduce the amount of atmosphere between you and the star, such as viewing something near the zenith rather than near the horizon, and/or viewing from a high altitude. The Sun and Moon are sufficiently large when viewed that the effects causing twinkling are not noticed. The highly-visible planets (e.g., Mars, Jupiter, Venus) rarely show such an effect, but smaller and/or more distant solar system objects can.