Fish aren't too bright, and sometimes they aren't trying to do anything. At one pet store I frequented, there were some fish who'd all get stuck face first in a series of pipes that were in their tank. Every night the pet shop owner had to pluck them all out so they'd not die overnight. In this case they weren't trying to do anything other than investigate the hole they'd already forgotten about and they'd get stuck.
However what you describe sounds like it may actually be injured and trying to hide. Weak fish (sick, old, injured) will avoid open water. Do you have other places for the fish to hide? Can you block the filter with plants or ornaments?