The immune system is one of the most complicated and wonderful pieces of biology. It's also scary in the ways that it can malfunction and the challenges it presents to modern medicine.
> What is it about the foreign cells that is identified as foreign by the host cells?
The MHC system is a major determinant of histocompatibility.
https://en.wikipedia.org/wiki/Major_histocompatibility_compl...
https://en.wikipedia.org/wiki/Human_leukocyte_antigen
https://en.wikipedia.org/wiki/Histocompatibility
MHC is an adaptive immune function used to detect foreign antigen that was evolved as a means to combat intracellular pathogens. This cell-surface machinery collects and presents foreign antigens from inside the cell at the cell surface for discovery by immune cells that come into contact. If something "foreign" is found on the MHC, the immune system targets the cell for deletion and upregulates the immune system for further attack.
The genes that code the MHC proteins vary widely between individuals. This can be beneficial as viruses struggle to evolve in a way that evades all MHCs in a population.
Unfortunately, the MHC proteins are themselves a highly reactive antigen that triggers the immune system. Luckily, the body learns during a process called "negative selection" to cull any immune cell receptors that recognize your own MHCs:
https://en.wikipedia.org/wiki/Thymus (search "negative selection").
If any of your own T-cells match your own MHC, they're killed. Unfortunately, your body doesn't know the shape of MHC proteins from donor tissue and can't learn to kill any TCRs that match. And these proteins are incredibly, incredibly polymorphic:
https://en.wikipedia.org/wiki/Human_leukocyte_antigen
Search "variability", then multiply the numbers -- you're not going to find an exact match for you anywhere, unless you have an identical twin. This is why donor databases exist. If you can find a match for one of the variants, it reduces the product of these multiples.
It's very hard to find a tissue match.
When you transplant foreign tissue, it's an antigen.
Fun fact: did you know your immune system genes aren't at rest and are actually evolving right now? Your immune cells run stochastic hill climbing. It's wild. Check out somatic recombination:
https://en.wikipedia.org/wiki/V(D)J_recombination
The immune system is incredibly complicated.