This is usually because of one of two things or sometimes both together.
When a fish is being bullied or attacked, it will hide. It is scared so it hides. Often a new fish added to a tank will hide until it gets a feel for its new envrtonment and prefers to stay hidden until it gets the "lay of the land." In such cases it will begin to act more normally as it adjusts.
When a fish is sick in some way- it is stressed and weakened. So it will hide. It also does this because when it is not at its best, it knows it may be open to being bullied or attacked.
Usually, if it is just being bullied the fish will come out for food. If it is ill it may not do this.
Finally, some fish are just natural hiders because it how they survive.
edited to add the following below
Of course fish will retreat to hiding in a tank being cycled. Ammonia and nitrite are nasty things and they will cause a fish to feel really badly and it can even be fatal. This is not a disease, it is a problem with water parameters. But the fish feels like it is sick from these things even though they are no diseases or parasites etc. per se.