Let's look: "It house is big and expensive." (What???) Or, on the other hand: "That house is big and expensive." (Much better) When "det" is not accompanied by a noun, it means "it", because it IS the noun you're talking about. When it precedes a noun, it is specifying something about the noun.
I was commenting on this to a Danish person just the other day. I very often find that when I'm trying to understand the real meaning and intent of a Danish phrase in English, it is better to set aside my American English and instead, think of 19th century British English, like something by Dickens, Austen or the Bronte sisters. And yes indeed, that dear little house could be quite dear. ;-)
It does relate to the gender of the noun, you use "det" for neuter nouns and "den" for common gender nouns.
"Et æble - æblet - det æble - dette æble" > an apple - the apple - that apple - this apple
"Et bord - bordet - det bord - dette bord" > a table - the table - that table - this table
"En hund - hunden - den hund - denne hund" > a dog - the dog - that dog - this dog
"En stol - stolen - den stol - denne stol" > a chair - the chair - that chair - this chair
So, this is getting into a lille more complex part of grammar. In the examples you mention you have two options.. depending on the rest of the sentence.
If "owner of the noun" is the subject of the sentence you can still use the "sin/sit" even if the subject is not a person. Or you can use "dens/dets" (det/den + the possessive S) which relates back to the gender of the subject.
The dog takes a walk without its collar. - Hunden går en tur uden sit/dens halsbånd. (note that "sit" relates to "halsbånd" while "dens" relates to "hund")
The table is leaning to the side with its crooked legs. - Bordet læner til siden med sine/dets skæve ben. (Note: "sine" relates to the plural "ben" and "dets" relates to "bord")
If the "owner of the noun" is not the subject of the sentence, then you have to use "dets/dens".
The owner takes a walk with her dog and its ball. - Ejeren går en tur med sin hund og dens bold.
I am sitting at the table with its crooked legs. - Jeg sidder ved bordet med dets skæve ben.
- edited to fix catastrophic language mix-ups in one sentence
(Source: https://sproget.dk/raad-og-regler/typiske-problemer/hans-hendes-eller-sin/hans-hendes-sin-uddybning (which is in Danish))