Unspent/Spent Flag in Blockchain
It is important to understand that the spent flag you are talking about, is not a field of an output that is stored in the blockchain. It is rather created internally by the client interacting with the blockchain. The only fields of information of an output that is permanently stored on the blockchain are:


The Amount
The Locking-Script Size
The Locking-Script


All the full nodes on the bitcoin network checks if an output is spent or not by checking if the output is part of a structure called the UTXO set. In this structures all nodes keep all outputs which has not yet been spent at the last block of the blockchain the nodes have validated. If an output is part of the UTXO set, it means that the output is unspent. 

For every new block in the blockchain, the nodes validates the block and removes any previous outputs in the UTXO set, that has been used as inputs in the new block.

Since a new node validates the blockchain by starting from the first block ever, called the genesis block, and updates UTXO set for every block in the blockchain, the UTXO set will contain all current unspent outputs once the node is synced with the rest of the network.