That's not what happens. 51% attack can undo the last blocks and replace them with new blocks, but the blocks still have to be valid. They can't edit the blockchain and transfer someone's bitcoins.
That's not totally true. If you look at what Bitcoin Gold did (I believe that's the fork that did it) they actually reorganized the forked chain to unlock satoshi's coins for their dev team.
that was not a 51% attack
that event on the altcoin was rewriting the protocol code.
nothing to do with a 51% attack
if it involves changing the rules where a certain percentage of the network are not in agreement (contentious) where code changes are involved thats called a FORK. not a 51% attack