Completely agree that it's the longest valid chain that wins. But it is not always possible to know if a selfish transaction is invalid. The validity rules embedded in the software can check for some invalid situations but not for every possible invalid situation. If validity rules were able to check for every invalid situation there would be no 51% attack (
https://www.investopedia.com/terms/1/51-attack.asp).
Kog is correct, you're not.
The validation in Bitcoin Core and similar other wallets will check each and every transactions for their validity. It is simply
impossible for someone to broadcast a transaction that does not follow the network rules to the network and expect anyone to accept it. It won't be relayed and it won't be accepted, its that simple.
51% attack doesn't involve anything invalid or the breaking of rules. 51% attack is just the downside with the way that the system is designed and it is not possible to be avoided. Bitcoin hinges on the fact that whoever has the largest POW is the correct person. 51% attack is when a miner attempts to spend the inputs of a previous transaction and use their block to essentially "replace" it. You cannot break any of the network's rule (ie. create coins out of thin air), or else you're on your own fork. Please read the post that has been written thoroughly.