Continuity on paths implies continuity on space?

In general, the answer is negative. For instance, let $X=\Bbb Q$ endowed with the standard topology (or, more general, a non-discrete space which is hereditarily disconnected (that is, it has only one-point connected subsets)), $Y=X$ endowed with the discrete topology, and $f$ be the identity map (which is discontinuous). Nevertheless, any map $\gamma: I\to X$ is constant, so the composition $f\circ \gamma$ is continuous.

On the other hand, the claim holds when $X$ is a first countable (that is, it has a countable base at each its point) locally pathwise connected space (that is, for every $x\in X$ and each neighborhood $U$ of the point $x$ there exists a neighborhood $V$ of $x$ such that for any $y\in V$ there exists a continuous map $\gamma: I\to U$ satisfying $\gamma(0)=x$ and $\gamma(1)=y$). Indeed, let $x\in X$ be an arbitrary point. By induction we can construct a sequence $\{U_n:n\in\Bbb N\}$ of open neighborhoods of the point $x$ such that $\{U_n\}$ is a base at $x$ and for each $n$ and each $y\in U_{n+1}$ there exists a continuous map $\delta: I\to U_n$ satisfying $\delta(0)=x$ and $\delta(1)=y$. Assume that the map $f:X\to Y$ is discontinuous at the point $x$. This means that there exists a neighborhood $W$ of the point $f(x)$ such that for any neighborhood $U_n$, $n\ge 2$ there exists a point $x_n\in U_n$ such that $f(x_n)\not\in W$. We can easily construct a continuous map $\gamma_n:\left[1-\frac 1{n-1}, 1-\frac 1{n}\right]\to U_{n-1}$ such that $\gamma_n\left(1-\frac 1{n-1}\right)=x_n$ and $\gamma_n\left(1-\frac 1{n}\right)=x_{n+1}$. Now define a map $\gamma: [0,1]\to X$ by putting $\gamma(t)=\gamma_n(t)$ if $t\in \left[1-\frac 1{n-1}, 1-\frac 1{n}\right]$ for some $n$ and $\gamma(1)=x$. Since for each $n$ the set $U_n$ contains a set $\gamma_m\left(\left[1-\frac 1{m-1}, 1-\frac 1{m}\right]\right)$ for each $m>n$, we see that the map $\gamma$ is continuous. But $f\gamma(1)=f(x)$ $f\gamma\left(1-\frac 1{n}\right)=x_{n+1}\not\in W$ for each $n$, so the map $ f\gamma$ is discontinuous at the point $x$.