You can just as easily describe the behavior of immune cells as categorizing cells into 'healthy' and 'unhealthy' and killing the 'unhealthy' cells. Suddenly the disease is not about internal conflict, but about internal hygiene. And when the immune system kills 'foreign' cells, it's not because they are foreign, but because they are found to be 'unhealthy': deviating too much from what it considers 'healthy'.
This is a simpler explanation. Apply Occam's razor: the immune system does not care about whether something is 'foreign': that's a more complex, and more precise, judgement than is needed to determine whether something needs to be killed. The broader category of 'unhealthy', deviating from the template/norm, is sufficient and that is the only thing the immune system needs to determine.
Instead it's dependent on the (specific to the individual) set of genes controlling the major histocompatibility complex, and so is very much a "self" ("derived from my genes") versus "non-self" ("not derived from my genes") determination.
The immune systems primary function is housekeeping: killing cells that are still completely 'self', but are old, worn down or dysfunctional in some other way. Killing 'invaders' and cancers is minor in terms of the numbers of cells destroyed.
As your transplant example shows: something foreign can be found to be entirely 'healthy' by your immune system. So self vs. foreign is too narrow.
Autoimmune diseases occur when immune cells improperly categorize some "self" cells as "non-self" and trigger immune response on them.