Those two blocks can never exist in the same chain. Whichever one came in the later block would be invalid because it would attempt to consume an unspent transaction output that did not exist.
If those two blocks claim to be in the same chain, then nobody will ever recognize the later block as valid and it will be as if that block does not exist. If those two blocks are in different chains, eventually one chain will be clearly longer than the other, and that will be the one that makes that transaction forever valid.
It is also possible that some third chain, including neither of those blocks, becomes definitively longer. In that case, a miner is free to include that transaction in a third block, assuming that chain doesn't already contain a conflicting transaction.