Does the miner validate the transaction before putting it on the block for proof of work? my understanding is if the miner does not validate the transaction and published the block and the block gets rejected of the invalid transaction then miner will lose the reward? One more question does the nodes relay the transaction after validation or they just relay it?
Miner first validates all transactions he wants to include in the block he will mine.
Then from these transactions he calculates their Merkle root, that becomes the field of this block's header.
Then he mines (repeatedly hashes this header modifying its nonce field with each try).
When he finds the correct hash he broadcasts this block (including block's header and transactions) to the network.
Reasoning: It would be stupid from miner to do the expensive work of mining before making validation, risking the block to be rejected. This would mean he spent a lot of resources to mine the block in vain.
Nodes validate the transaction before relaying it.
Reasoning: It is beneficial for network if the nodes filter invalid (erroneous, malicious) traffic. It reduces the load.