The answer is in general no. More precisely, the following holds.
A finite map $f \colon C \to \mathbb P^1$ as in the question exists if and only if $\mathcal{O}_C(x-y)$ is a point of finite order in $\textrm{Pic}^0\, C$.
In fact, if $f$ exists, calling $n$ its degree we have $\mathcal{O}_C(nx) = \mathcal{O}_C(ny)$, that is $\mathcal{O}_C(n(x-y))=\mathcal{O}_C$, in other words the degree zero divisor $x-y$ defines a point of finite order in $\textrm{Pic}^0 \,C$.
Conversely, if $\mathcal{O}_C(x-y)$ is a point of finite order $n$ in $\textrm{Pic}^0 \, C$, then the two divisors $nx$ and $ny$ are linearly equivalent on $C$ and the linear pencil generated by them is a $g^1_n$ without base points. Thus such a $g_n^1$ defines a morphism $f \colon C \to \mathbb{P}^1$ of degree $n$, totally ramified at both $x$ and $y$.