Borel (1972, J. Diffl. Geometry) proved that $f$ is always algebraic if $Y$ is the quotient of a bounded symmetric domain by a torsion-free arithmetic subgroup. This is a super-generalization of your example 3 (the quotient of the complex upper half plane by $\Gamma(2)$ is isomorphic to the projective line minus three points). The proof uses a generalization of work of Kwack plus the resolution of singularities. I think there are abstract versions of this theorem, i.e., there are diffl-geometric conditions you can impose on $Y$, which are satisfied by the quotients in Borel's theorem, and which imply that $f$ is algebraic (but I'd have to look them up, or better, leave it to expert to answer).