It sounds like you’re asking how mosaic DNA works. Consider a set of fraternal twins (the kind with different DNA).
As embryos they develop to the point where their cells start to differentiate. One of the first things to differentiate is skin cells from bone, muscle and neural. If both twins recombine, the types of cells have changed but haven’t formed any organs yet. They can form one person out of two sets of DNA for different organs.
The reason the immune system can reject organs is because the way it recognises hostiles is by assuming that everything that isn’t itself is the enemy. It looks at certain molecules (called antigens) on the surface of cells, and if those molecules aren’t the molecules its expecting to see, it declares war.
The immune system doesn’t innately know what *not* to kill though – it has to be trained. This happens very early on in fetal development, but it happens *after* the chimera process normally occurs. When it happens, any antigen that’s currently part of the body gets put on the “treat this as self” list. If the body is a chimera, then every kind of antigen found gets put on that list. Every cell in your body (except the bacteria) is descended from a cell that was present when the immune cells were taught who you were, and so expresses the same antigens and is tolerated by the immune system.
Also, fun fact – all women are a little bit chimera-ish. As you may be aware, there are things called the X and Y chromosomes. In humans, men have one X and one Y in each cell, and men have two Xs. However, having two Xs actively being used at once causes problems, so during development (before the immune system is trained) every cell switches one of its Xs off at random, meaning that 50% of the cells express one X and 50% express the other. That’s passed on to all cells they create too. It’s not full blown chimera, but it’s not entirely dissimilar – half a women’s cells are expressing different genes to the other half, even when doing the same job.
It helps that while the cells are different, that are from the same parents so they are less likely to be rejected. Like getting a kidney transplant from your sibling. But even then it can lead to autoimmune disorders.
There’s also a bit of survivorship bias here. If the cells aren’t compatible the person wouldn’t survive to be an adult.
Your body recognizes early in its development what is itself and what is not itself. So if you are a chimera person that was formed from two fraternal twins that joined very early in embryonic development, when only a few cells, your body’s immune system recognizes all of your cells as being friendly and won’t attack them, even though you have 2 different sets of DNA. But when you get an organ transplant, you’re older and your immune system has already recognized what is yourself and what is not yourself. So it’s too late to train the body to recognize the foreign organ as yourself and friendly. So your body will see the organ as foreign.
A side note: organ transplant experts have been trying to change this. They have some techniques in development now. So for example, they might given a recipient some bone marrow from the donor. Bone marrow makes white blood cells, which are part of your immune system. the idea is that now your immune system will be partly the donor’s immune system, so will be less likely to attack the donated organ since it recognizes the organ’s DNA as itself. And a very young baby is going to be less likely to reject an organ because its immune system is still developing and is not necessarily going to react as negatively to something foreign.
Latest Answers