Below is the Wikipedia explanation of the phenomena:
Sundogs may appear as a colored patch of light to the left or right of the sun, 22° distant and at the same distance above the horizon as the sun, and in ice halos. They can be seen anywhere in the world during any season, but they are not always obvious or bright. Sundogs are best seen and are most conspicuous when the sun is low.
Sundogs are commonly made by the refraction of light from plate-shaped hexagonal ice crystals in high and cold cirrus clouds or, during very cold weather, these ice crystals are called diamond dust, and drift in the air at low levels. These crystals act as prisms, bending the light rays passing through them with a minimum deflection of 22°. If the crystals are randomly oriented, a complete ring around the sun is seen—a halo. But often, as the crystals sink through the air, they become vertically aligned, so sunlight is refracted horizontally—in this case, sundogs are seen.
As the sun rises higher, the rays passing through the crystals are increasingly skewed from the horizontal plane. Their angle of deviation increases, and the sundogs move further from the sun. However, they always stay at the same elevation as the sun.
Sundogs are red-colored at the side nearest the sun. Farther out the colors grade through oranges to blue. However, the colors overlap considerably and so are muted, never pure or saturated. The colors of the sundog finally merge into the white of the parhelic circle (if the latter is visible).
It is theoretically possible to predict the forms of sundogs as would be seen on other planets and moons. Mars might have sundogs formed by both water-ice and CO2-ice. On the giant gas planets—Jupiter, Saturn, Uranus and Neptune—other crystals form the clouds of ammonia, methane, and other substances that can produce halos with four or more sundogs.