Away from the zeros of $X$, it's always locally solvable. Just put $X$ in flowbox form, i.e., $X =\partial_x$. Write $Y = u\ \partial_x + v\ \partial_y$, and the equation uncouples into the pair of equations
$$
u_x = f\ u\qquad v_x = f\ v.
$$
If you now write $f = g_x/g$ for some $g>0$, then the solutions are of the form $u = u_0(y)g$ and $v = v_0(y) g$ for some functions $u_0$ and $v_0$ of a single variable. This is all in a local flowbox chart, of course.
Near zeros of $X$ you could run into trouble. For example $X$ might be the vector field that represents rotation about a point, so that it has a center at that point. Then there won't be a nontrivial solution near that point if you specify that $f>0$ near there.
Globally, other obstructions could show up. For example, $X$ might have closed flow lines and a nontrivial Poincaré return map, and so on. Or it might have a dense flow line. Lots of things could happen. I'm not sure you want to try to come up with a general criterion, rather than be aware of what you have to consider in patching the local solutions in any given case.