When does a node mark a transaction as confirmed or unconfirmed?
They don't know about the new block until they receive it over the peer-to-peer network (or some other way, e.g. FIBRE).  But since it was broadcast to the network, and all nodes on the network will be trying to relay it to all their peers, this should happen pretty quickly.
When they receive the block, they know to exclude those transactions in their own blocks.  (In practice, they probably generate a whole new candidate block, including only transactions not already confirmed, and with a new header that lists the just-received block as its parent.)
When the node changes its mind about which branch is active, transactions from the previously active branch (subsequent to the block where they diverged) are returned to the memory pool, except for those which are already in the new active branch, or conflict with a transaction on that branch.  Then, just like all other transactions in the memory pool, they are eligible for inclusion in future blocks created by this node.