When miners build valid blocks with transactions, they put in significant amount of compute work to generate a hash of the block header that meets the difficulty requirement. Blockchain is a chain of blocks where each block header references the hash of the header of the previous block. The hash of the block header is calculated using all the elements of the block, which includes the transactions it contains. If a component of the block is changed in any way, it will generate a completely different hash.
Confirmation is a direct reference to the difficulty of removing a transaction from the blockchain. If a transaction is included in a block that has 5 blocks mined after it, then an attacker who wants to exclude that particular transaction would have to perform "work" (compute hashes that match the difficulty requirement) to mine the block containing the transaction and all subsequent blocks after it. This is a total of 6 blocks and hence that particular transaction is said to have 6 confirmations.
If the transaction is mined in a block with sufficient confirmations, than the cost of excluding that transaction is very high as the attacker would have to perform the compute work. Thus, in the mining process the miners through their heavy compute work add finality to the transactions.