Lets take the "classic" Halley's comet. It is made of ice and dust (a dirty snowball). As it approaches the sun, two things happen:
1) The ice starts to melt, and because it is effectively in a vacuum is transitions directly from ice to water vapour. The dust is also released.
2) The "solar wind" pushes the water vapour and dust away from the comet's nucleus. (This is why the "tail" of a comet always points away from the sun, rather than streaming out behind the comet)