What makes a cancer contagious?
There are two relatively common contagious cancers: Tasmanian Devil Facial Tumor, and Canine Transmissible Venereal Tumor.  Both are truly contagious cancers, in that the cancer cells themselves are transmitted from one host to the next, and expand and cause disease in each successive host.  (There was also a contagious cancer of hamsters, which has long since gone extinct, and there are some transmissible tumors in clams and oysters; the latter don't have immune systems that are remotely similar to dogs, Devils, or humans.)

It's believed that one key aspect of the Devil Facial Tumor is that Tasmanian Devils are immunologically closely related.  Normally, cancer cells from one host would be a tissue graft in a different individual and would be rapidly rejected as with any allograft.  However, immunologically closely related individuals can tolerate each others' grafts, and it's believed that this is part of what allows the Devil tumor to spread -- a lack of genetic diversity among Tasmanian Devils.  


  Major histocompatibility complex class I and class II genes have extremely low levels of sequence divergence in the devil population from the Tasmanian east coast (Siddle et al., 2007a, 2007b). ... The lack of diversity at MHC loci, coupled with weak responses of east coast devils to allogeneic mixed lymphocyte culture, has led to the suggestion that this population may be functionally identical at MHC loci, thus permitting the spread of DFTD as an allograft.


--Clonally transmissible cancers in dogs and Tasmanian devils

The genetic diversity explanation is widely accepted, but it hasn't been formally proven and there are a number of points that suggest that it isn't the whole story.  There are several other molecular features of the tumor that probably make it less immunogenic (see the review The role of MHC genes in contagious cancer: the story of Tasmanian devils) and the full story probably involves a combination of these things.

CTVT is different.  It's astonishingly ancient (it apparently arose in a dog, or a wolf, 11,000 years ago and has been passed from dog to dog continuously since), so it's obviously very successful at what it does, but it's not at all understood how it does it. Dogs are genetically pretty diverse and definitely don't tolerate arbitrary grafts from each other, so that's not the explanation. Lots of other possible explanations have been put forward, most of which point to various immunological features of the tumor; however, while that's clearly an important point, none of the things people have implicated are unique to CTVT -- tumors invariably have immune suppressive abilities and don't have the same ability to spread. (Going back to the Devil tumors, the low expression of MHC molecules on the cancer cells is probably a factor there too, but it's important to understand that low MHC expression is almost universal among tumors, including the vast, vast majority that can't transmit.) 

Summary:


There do exist a very small number of truly contagious cancers.
The reasons for their transmissibility are not fully understood.
Genetic diversity and immune evasion are probably two of the causes.