Question:Why do comets sometimes have tails?
Comets are heated by the Solar Wind.
As the comet gets closer to the Sun this heating becomes sufficient to melt part of the comet, the melted material trails behind the comet to form the distinctive tail.
The solar wind is the stream of energetic particles that are constantly thrown out of the Sun.
The solar radiation and the solar wind both push the tail of the comet away from the Sun so the tail always lies behind the comet in the direction pointing away from the Sun.