edit: I originally had some points about the inefficiency of RTGs, but after some more research prompted by @Jeremy I found that it's not really a valid point when they're used appropriately for the spacecraft's mission. The RTGs used by Galileo at Jupiter generated 300W of power, whereas the solar panels that will be used by Juno at Jupiter will generate 450W of power. Solar arrays are also much larger and heavier than RTGs and impact the delta-V budget of the spacecraft, a costly interaction. The reason that solar arrays are used in some spacecraft are outlined in the points I make below so the efficiency factor doesn't really come into play.
Radioisotope Thermoelectric Generators (RTGs) are used when a spacecraft will be venturing too far from the sun to get enough power from it, or when it experiences extended periods of darkness while still needing to operate. This is the case with the Pioneer missions, Voyager missions, the Cassini missions, as well as the science experiments left on the moon during Apollo, and surely more that I haven't thought of.
RTGs are dangerous, especially if the spacecraft fails during launch, or an earth-flyby goes badly (this could spread radioactive material across a continent), and don't generate much power when compared to solar panels in close proximity to the sun.
Solar panels are used for missions that will almost always have a clear view of the sun, where they can generate much more power than RTGs can.