Intellect devourer is not an object
It is an aberration of tiny size.
Nothing states, that they are one and the same entity.
Note, that it is possible to save the host. Furthermore rules state about Intellect devourer leaving the host, when he drops to 0 hp. The host and the Intellect Devourer are two seperate creatures.
How will polymorph work?
While inside a creature, the intellect devourer has total cover against attacks and other effects originating outside its host.
You cannot affect the intellect devourer itself, but only the host.
True polymorph
Choose one creature or nonmagical object that you
can see within range.[...]
The only thing, you will see is once again, the host, not the intellect devourer. Accordingly, to the spell's decription, only one creature will be affected and that will be the host.
What will be the effect?
Despite the fact of being polymorphed, the host is still the same creature.
The effect will be a dog with the intellect devourer inside it's skull. Because True Polymorph usually affects mental ability scores it is possible to notice, that something is wrong, as the dog will have an Intelligence of 12, instead of 3.
A Building Is An Object
Whilst the rule you are referring to states:
For the purpose of these rules, an object is a discrete, inanimate item like a window, door, sword, book, table, chair, or stone, not a building or a vehicle that is composed of many other objects.
You have to keep in mind that this quote was taken from the Objects section and the rules the quote is referring to are about object Hit Points. The table for them only goes from Tiny objects to Large ones, it does not give Hit Points for Huge or Gargantuan objects, such as a house or a mansion (some exceptionally buildings may even be composed of several Huge or Gargantuan objects).
From page 247 of the DMG:
You can track a Huge or Gargantuan object's hit points if you like, or you can simply decide how long the object can withstand whatever weapon or force is acting against it. If you track hit points for the object, divide it into Large or smaller sections, and track each section's hit points separately.
Firstly, this shows that Huge and Gargantuan objects exist. Second, this also shows that objects bigger than Large only need to be tackled in smaller portions if you’re dealing with the Hit Points of the objects that make up a larger object.
So yes, you can pass through the ground or a building as they are both considered to be objects.
Also, in regard to this question:
Is there anything that has mass and is neither a creature nor an object? If so, please provide examples and indicate whether it falls into an explicit class of its own, analogous to objects and creatures.
Yes, Fluids - air, water, poisonous gas etc. They all have mass but they are not objects in the same way a book is an object. They are not things you could break, or grasp, or shape or manipulate, not in the same way way you could with something more tangible. A container for a fluid would be an object, but not the fluid itself.
I would argue, for the purposes of your spell, fluids do not count as objects (or, at the very least, they do not count as solid objects as they are fluids) so you could teleport into, reemerge inside them, be moved into them or whatever else you want as, because they are fluids not solids, they would move around your physical space. A fluid like water or oil might though be difficult terrain and require a swim speed, a lack of a fluid like oxygen or too much of a fluid like carbon dioxide or other poisonous gases would cause Suffocation. I don’t believe the term Fluid is used to describe things that are non-objects, non-creatures in the books but it seems an appropriate term to use.
Beyond fluids? Anything smaller than a Tiny object is not considered to be an object, anything smaller than a Tiny creature is not considered to be a creature. Perhaps Minuscule would be an appropriate term to call anything smaller than Tiny that isn’t a fluid.
Best Answer
The nice answer by Mindwin handles the particular example well; but it partially sidesteps the problem by stating that any creature can squeeze in a 15×15 space, let alone a 30×30×30 volume. This is a correct statement as far as rules are taken as written. It also makes sense if we assume that D&D designers took real-life creatures as a means of gauging the possible sizes of living beings in general. The largest creature that has ever lived on Earth is the blue whale. It can be 170 tonnes in weight, assuming the density of water, that corresponds to over 6000 cubic feet. So even a blue whale would occupy about 20% of the total volume created by the Demiplane spell.
However, this answer might not satisfy those of us who play the game less from a gamist perspective, but more from a simulationist one. A blue whale is 100ft long, so while its total volume is small enough to fit, you would need to fold the poor animal. What happens in that scenario is up to each DM. The folding might harm the animal (possibly killing it) or the pressure by its body might be large enough that it tears the boundaries of the Demiplane. In the case of the Tarrasque, it being a siege monster and being able to consume just about anything, it would be logical to assume that it would attack the walls. Finally, we can always imagine magical creatures that are larger than whales or Tarrasques; for example Rocs have wingspans longer than 200ft; assuming the picture in the Monster Manual to be correctly proportioned, its abdomen alone is comparable in size to that of the Tarrasque.
Hence, if we assumed there were a creature that would not fit into the space generated by the Demiplane spell (as the title of the question states), and assuming that it can still be targeted by True Polymorph (I write this as we have already gone beyond RAW creatures), what would happen at the end of the Polymorph's duration is up to individual DMs. I would personally rule that (1) the creature will get compressed and harmed and possibly killed; (2) if the creature's 'pressure' is large enough to break the wooden/stone walls of the room, the Demiplane's boundaries would be ruptured. In that case, just like a ruptured Bag of Holding, the contents could spill into the Astral Plane. (Or to the Ethereal Plane if you assume Demiplanes are in the ethereal, following the conventions of earlier D&D editions.)
The creatures would not be ejected to the nearest unoccupied space, as the Demiplane is not on the prime material plane. We read the casting of the Demiplane spell creates the space, and that we can connect to such spaces with future castings of the spell from other locations, this implies that the Demiplane is not tethered to any specific location in the prime material.