Why do comets have tails?

Why do comets have tails?

Available on Prime Video
S1 E23: Adi and his alien pet Woops go out to discover space on board their spaceship. They explore planets, stars, comets and other curiosities of the Universe.