If your doing a search in the searchbox not the search page its like this
On the index page the cat variable is empty so it is set to all on the search so its pulls entries everywhere
when you are in a category the cat that is searched is the cat your viewing so if that cat specifically for matching entries.
IT DOES MATTER IF ITS A MAIN CAT OR SUBCAT. If you are in a main cat that contains no pictures you will not get a search result. The searchbox only pulls entries from the cat it is in