The MMSI number is supposed to stay with the boat across owners. Unfortunately the various issuing agencies and systems don't make that very easy. All seem to have bee built with an eye towards issuing numbers and not so much towards boats that change ownership.
In contrast, an FCC Ship's Station license DOES NOT follow the ship, but rather terminates when ownership changes. Actually, you need to cancel it when you sell your boat.
I haven't tried this myself, but I believe both BoatUS and the FCC provide a way to pick up an existing MMSI number and carry it forward to a new owner. If you buy a boat that has one already assigned, this is what you should do.
The other thing you need to do if you buy a boat with AIS is go in and change the broadcast boat info on the AIS. Unfortunately, lots of people seem to just ignore it all. I have owned and sold two boats with AIS, and both are still running around broadcasting themselves under the original name I gave the boat. One of them has changed hands 3 or more times and been renamed each time, but it still broadcasts itself as my original boat name.
There has been lots of effort to get AIS out there and used with good info, and now that those boats are changing hands, the data is getting all messed up again.