Often in nature, if a fish is out in the open where it can be clearly seen, it winds up as another fish's dinner. Many species of fish hide in fish-tank decorations such as plastic plants, rocks or tunnels or even try to hide behind the tank equipment. Some species, like any of the plecostomus sucker fish, prefer to hide during the day but become more active when the lights go out. FishGeek.com notes that any new fish introduced into an aquarium almost always hides because it is wary of what might be in the new tank.
Being Bullied
Fish also actively seek out hiding places if they are being harassed by other fish. This could be a male harassing a female as part of the spawning process, but it also could be one species (like a tiger barb) deliberately bullying smaller or slower-swimming fish (like a male betta). According to "Freshwater Aquarium Problem Solver" (David E. Boruchowitz, 2006), fish even try to bury themselves in gravel to get away from a harassing fish.
Scary Stimuli
Fish hide when they are frightened. Hiding places help protect the fish from too much stress because they know they have them available when danger threatens. Anything striking the tank---even tapping on it---can scare fish. Any new filter, heater or air pump may cause the fish to hide at first because they are not used to the vibrations that the equipment produces. Very loud noises like a blaring television can also scare fish.
Guarding Territory
Some fish, such as those in the cichlid family, seem to be hiding when they are actually guarding territory so they can raise fry. These fish can be incredibly defensive when guarding this territory, even to the point where all other fish in the tank need to be removed, or else they'll be killed.