Nodes are by default refusing to propagate invalid transactions to other nodes and might even disconnect from a node that makes too many invalid transactions. So it's not like even the whole network rejects an invalid transaction - it doesn't get the chance to spread through the network at all.
Mining works similarly. When miners find a block, they send it to the nodes, and then the nodes spread it further. If a block is invalid for some reason - it has an invalid transaction or miners tried to cheat with pow - the nodes would refuse to accept and propagate it. So miners have a huge incentive to make sure that everything is correct, otherwise they'll just waste a lot of money.