Assume your desired compound A is dissolved in a solution and you are trying to extract it from solid contaminant B. You would use gravity filtration because vacuum filtration uses a vacuum, as the name suggests, and as a result it cools the solution. When a solution becomes cooled, the solubility of A in the solution will decrease, and more will precipitate out. As a result, you get a lower percent yield and so you use the gravity filtration.
In another scenario, if the solid B is your desired product, you can use vacuum filtration because prior to filtration you should have cooled your test tube in ice to maximize precipitation. So using a vacuum filtration would not only be faster and more efficient, but would keep the solution cooled, so that B doesn't redissolve into the solution.