Let's say John gave 5 BTC to me. So, John took his unspent outputs and put it into inputs to create a transaction. Let's say John already had a transaction which was holding exactly that amount of BTC.
Now, How can John not spend 5 BTC anymore ? The output John used to give me 5BTC is still on Blockchain. So, does node go to that output transaction and mark it as spent ? how does it mark it as spent?