There is no need to assume that $X$ is compact, connected, or a manifold in your first claim. Anyway, here is some context in which to put this question. A morphism $G \to S^1$ of Lie groups gives a map $BG \to BS^1 \cong B^2 \mathbb{Z}$ of classifying spaces, and hence a cohomology class in $H^2(BG, \mathbb{Z})$. If $G$ is connected, $BG$ is simply connected, and hence
$$\pi_1(G) \cong \pi_2(BG) \cong H_2(BG, \mathbb{Z}).$$
Now, by universal coefficients, we have an isomorphism
$$H^2(BG, \mathbb{Z}) \cong \text{Hom}(H_2(BG, \mathbb{Z}), \mathbb{Z})$$
from which it follows that every morphism $\pi_1(G) \to \mathbb{Z}$ corresponds to a map $BG \to B^2 \mathbb{Z}$ of classifying spaces, and hence to a map $G \to S^1$ of $\infty$-groups (meaning, loosely, a group homomorphism up to coherent homotopy). The remaining question is when we can strictify a map $G \to S^1$ of $\infty$-groups to a genuine Lie group homomorphism.
As Anton says in the comments, this is not possible if $G$ is noncompact, and $SL_2(\mathbb{R})$ is an explicit counterexample (the point being that the inclusion $SO(2) \to SL_2(\mathbb{R})$ of the maximal compact is a homotopy equivalence). It's less clear to me what happens when $G$ is compact. Certainly if $G$ is itself a torus it's always possible. On the other hand, if $G$ is semisimple then $\pi_1(G)$ is finite, so admits no nontrivial homomorphisms to $\mathbb{Z}$. So it might be possible to construct a more exotic counterexample by taking something like $SU(2) \times S^1$ mod $(-1, -1)$? I haven't thought much about these groups.