Miner modify pending block (not yet on chain) and successfully solve the PoW
It is perfectly possible, and it is why it is discouraged to take irreversible action based on transactions that are unconfirmed (=not in a block yet).

However, the transaction is not invalidated just because it is reversed. Another miner can still include it at a later time, unless you issue a conflicting transaction  (=double spend) with a higher fee.