If proof of work is a consensus algorithm that guards against malicious nodes from adding faulty blocks, what actually happens when a miner successfully confirms a fraudulent block (i.e. a block that contains double spending transactions or other fraudulent transactions) by nonce guessing? In order for a miner to extend the “correct” block, there has to be some way to validate individual transactions in a broadcasted solution. If validation is simply checking whether the same inputs (transactions, nonce, etc) leads to the same hash, then there is no method for distinguishing blocks that contain faulty transactions and blocks that contain only true transactions. What is this algorithm that miners use to validate individual transactions in a broadcasted solution before deciding to abandon the block they are currently working on?
What algorithm do miners use to validate individual transactions in a broadcasted solution before accepting it to their blockchain?
Fully validating nodes have parsed the complete blockchain in order to autonomously determine the set of Unspent Transaction Outputs (UTXOs). When such a full node learns about a new block it checks that the block header is well-formed and then validates every single transaction. One part of the transaction validation is to confirm that all of the UTXOs the transactions are spending are available for spending (and only spent once). Blocks also have to fulfill a few other rules:
(Note: I haven't verified whether this article on the Bitcoin Wiki is up-to-date)
If a block is noncompliant to any single rule, any full node will recognize this and reject the block. This famously happened to AntPool on July 10, 2019, when they published a block that collected a greater block reward than allowed (highlighted in rules screenshot). AntPool did the work, but the block was invalid and immediately rejected by the network.
All nodes, not just miners, check that the inputs to transactions in a block have not already been spent. All full nodes (wallets such as Bitcoin core) keep track of unspent transaction outputs (UTXOs).
No nodes trust other nodes, no nodes trust miners. All nodes check (validate) everything that can be validated.
For a node to accept an invalid transaction, that is, one with an invalid UTXO, inexistent balance or already spent balance, that node should need to slightly change the code and, by doing that, it will be, de facto, withdrawing itself from the 'consensus' and as such, the maximum aspiration of that said node would be to become a fork if some other nodes would install or follow that modified code.
It is just impossible to achieve what you describe and that is why every 10 minutes on average we are confirming blocks following the strict consensus that those UTXOs or balances associated with an specific TXID and Index were not spent before.