Some health issues, such as injuries, illnesses, or joint pain, may cause dogs to seek small spaces for comfort. If your dog is suddenly hiding in the closet and also showing other signs of discomfort or pain, you should consult a veterinarian to determine if there's an underlying health issue.