and how does it ensure that all nodes in the network agree on the validity of each transaction through the process of transaction verification?
Each node validates the transactions and blocks that it receives. It rejects any that are not valid. The implementation is in the node's software.
A node does not ensure that all nodes agree. Consensus is not enforced, it is only followed.
If a node considers a block to be valid when other nodes consider it to be invalid, then the chain will diverge into two branches, and that is called a fork. Nodes that consider one branch to be valid will follow that branch, and nodes that consider the other branch to be valid will follow the other branch.