The light rays get refracted by the miles of air in our atmosphere, and random pockets of cold / warm air causes the light rays to shift in random patterns – so the point-like light sources seem to twinkle.
Stars (except for the Sun) appear as tiny dots in the sky; as their light travels through the many layers of the Earth’s atmosphere, the light of the star is bent (refracted) many times and in random directions (light is bent when it hits a change in density – like a pocket of cold air or hot air). This random refraction results in the star winking out (it looks as though the star moves a bit, and our eye interprets this as twinkling).
Stars closer to the horizon appear to twinkle more than stars that are overhead – this is because the light of stars near the horizon has to travel through more air than the light of stars overhead and so is subject to more refraction. Also, planets do not usually twinkle, because they are so close to us; they appear big enough that the twinkling is not noticeable (except when the air is extremely turbulent).