I think your basic premise is a bit flawed.
You assume that a spaceship would be treated as the sacred "body" of its controlling AI, but I find this hard to believe.
I think the AI would, at best, own the spaceship and have some hardware considered the AI's body, or, at worst, be considered a non-physical entity without a body. As such, the spaceship, or anything else used or owned by the AI, would be subject to normal property laws, including inheritance where applicable.
Similar arguments work for other AIs, like houses, ocean ships, etc., but I'll focus on a spaceship for more concise writing.
The spaceship is a piece of property, not a body.
It's likely the spaceship was built explicitly for a purpose of human utility. As such, it will likely be the property of whatever person or corporation commissioned its creation, or later purchased it.
If AIs have legal rights, then they could certainly earn the money to purchase their own spaceship, much like I can purchase my own house or car. However, it's unlikely the spaceship would default to being owned by the AI, simply because a spaceship is a very costly item. And nobody would build spaceships if the AI built for the ship could just say "nah, don't wanna work for you" the instant they're turned on.
Many AIs would be designed with a modular "body", separable from the spaceship.
In a society where AIs are regularly treated as people and efforts are made to include them in design considerations, it's likely that each AI would have some kind of "body" that explicitly belongs to them at creation. This would likely include their main processing unit, and possibly a motorized contraption to allow the AI some physical autonomy.
I'm thinking something like a motorized wheelchair with a battery backup, a couple cameras, and a microphone, as well as the possibility for some type of physical manipulators (arms and hands) and some way to communicate (speakers and a monitor). This wheelchair (or high-tech equivalent) would carry the physical computer, allowing the AI to move from one spaceship to another.
AIs don't inherently have bodies.
However, for very advanced computer systems, it might well be the case that the AI doesn't have an explicit body. Many AI systems could be distributed across a single computer core, or a single AI could be distributed across multiple computer cores. It's likely many systems would have both: many AI systems sharing a network of multiple computer cores, such that no one computer belongs to a single AI, and no one AI is housed solely on a single computer.
In cases like this, the network would likely be scrubbed to remove traces of the dead AI (though some traces might be kept for sentimental reasons, much like Facebook keeps profiles for dead people around). Beyond that, the AI wouldn't necessarily have any particular ownership of the network. It's certainly improbable the other AIs would be forced to move to a new network so the old network could be disposed of.
Of course, the AI might have owned part or all of the computer network. In this case, normal property laws would apply. Well, as "normal" as you get for joint ownership of a common body.
The AI itself might have to earn independence.
Depending on your setting and the power of the AI, the AI could conceivably be an incredibly expensive device. An AI powerful enough to manage a large spaceship, space station, or an entire city, for examples, would likely fall into this category.
In the case of an extremely expensive AI, it seems likely that the AI would have a certain contract period where it's required to earn back it's own purchase cost. The laws around this would likely be complicated and vary from region to region, so we can't specifically enumerate them. However, there would likely be laws about maximum earn-back times (so a corporation can't keep the AI indefinitely if it's not making much money), and about work requirements (how much the AI has to work, and what kind of personal time the corporation needs to give it).
Physical "remains" would be treated according to the owner's wishes.
As many other answers suggest, I think the AI would be able to draft a will detailing how its property would be distributed, including any kind of hardware the AI lived on.
The AI could request that its spaceship be parked in a low-sun orbit, allowing it to slowly be consumed by the nearby star. Or request the ship be donated to the Martian Planetary Government to be used for scientific research. Etc.
Of course, the laws governing transfer or disposal of property after death might forbid certain types of request. An AI who owned another AIs body (or part thereof) wouldn't likely be allowed to dictate that the other body be destroyed. Instead, ownership would likely transfer to another entity, and the indentured AI would continue earning its freedom as usual, with the new owner dictating the AI's new workflow. Similarly, a spaceship occupied by hundreds of people couldn't simply be scuttled without properly evicting the tenants first.
Note that these laws wouldn't need to be specific to AI wills. A human who owned a spaceship or network cluster would be similarly restricted in how they could use, transfer, and destroy any property used by other entities, organic or otherwise.
Your addendum doesn't help much.
You've added an addendum (and a comment) stating that AIs are treated as free beings the instant they're created, who are able to choose whatever body they want.
This would not happen.
First, note that my above comment about forced service was explicitly about expensive, complex AIs. Run-of-the-mill AIs that don't cost much wouldn't necessarily need forced service if it's determined that most of them go on to be productive members of society anyways. But the really expensive stuff wouldn't get a choice. It's not about morality or legality; it's about physics and economics.
Next, your AIs simply wouldn't be given any arbitrary "body" they want in the form of buildings or spaceships. Not going to happen. Those things cost money and resources. Your AI could choose to work in a certain building for a while, but unless it earned the money to buy the building, it can't own it. Otherwise, you'll never afford new buildings.
A corporation can contract an AI to work in a specific building as the building manager, but the contract will include methods of terminating employment, just as it would for any human building manager.
Likewise, the corporation will not allow the AI to customize the building however it sees fit. The AI will be forced to conform to certain building standards, specifically so new AIs can be brought in if the old one moves on or is fired for whatever reason. And so the building can be torn down to build something newer and better in the future. Otherwise, you end up with a planet full of vacant buildings because the AIs can't be moved out and nobody can tear them down.
Going back to spaceships, you've got a little more freedom. Space is enormous, so you don't need to reclaim the tiny amount of wasted space taken up by an old spaceship. This means it's more likely an AI could eventually earn the spaceship as something it owns.
But you still have the same problems with cost. And spaceships will always be orders-of-magnitude more expensive than planet-based infrastructure. So even if the AI can legally purchase a spaceship for itself, it will have to work for a much longer time before it can afford to do so.
And again, practically nobody is going to just give a random AI a spaceship for a body so it can run off and do whatever with it. Because economics.
Finally, you're not going to have general-purpose AIs who can be good at whatever they want. Each AI will be purpose-built for specific types of things. Because the AIs are given people status (and we can't just destroy them when they're obsolete), there would be some level of all-purpose programming built in, so a house AI could work in most any house, a ship AI in most any ship, etc. But you're not going to put lots of wasted effort into building a house AI that's good at flying ships.
Spaceships and buildings aren't human bodies.
You can't just assert that the AI would automatically own the spaceship controls. As I've shown above, this doesn't make any sense in a realistic setting. But it also doesn't make sense from a logical standpoint.
Human bodies are required to sustain human minds, to drive human hands, to propel human feet. Likewise, an AI would have some amount of hardware required for it to function, which could be included as "part of the AI" upon creation (but doesn't have to be, as many AIs would likely be content to run on shared server farms as virtual entities).
But spaceships aren't required for pilot AIs to function, nor are buildings required for building manager AIs to function. And both of those items will be required by other entities for various reasons.
If human bodies had fairies living inside them, human skulls could easily be setup to detach from the body and transferred somewhere else, the bodies didn't require the head to avoid decay, the skulls could have their own implements for moving around and interacting with the world, and the human mind could easily be setup to process these different setups just fine; then human bodies would suddenly be a lot less sacred and personal. And this is the kind of analogy you need to use if you're going to compare the two.
Unless you're not really talking about AIs at all.
Let's say your civilization is so advanced it can just whip up a spaceship and give it out to the new AI. Likewise, it can whip up new planets and start building new houses on them when the old ones fill up with obsolete AI buildings. At this point, you aren't talking about any kind of remotely contemporary setting.
And, in all likelihood, there would be little-to-no distinction between what you're calling "AI", and normal people. Because who wants to live and die in some crummy, organic body, when they can have all their bits replaced by synthetic stuff? And a civilization who can whip up spaceships and planets on the fly, as well as being able to create sapient AIs, would certainly have figured out to convert humans to cybernetic bits.
At this point, you could potentially have giant spaceships with their own death rites, but you're also so far beyond current societal norms that any kind of answer to the question is purely guesswork.