Here's why:
* Direct objects are the nouns or pronouns that receive the action of the verb.
* In this sentence, the verb is "hiding."
* The object that they are "hiding in" is the "closet."
Note: The preposition "in" makes "closet" the object of the preposition, not the direct object. The direct object would be what they are hiding, not where they are hiding.