When is the Lie algebra of the center of Lie group the center of its Lie algebra

Suppose that $G$ is a Lie group with Lie algebra $\mathfrak{g}$ and the center of $G$ is denoted by $Z(G)$ with its Lie algebra denoted $Z(\mathfrak{g})$. It's easy to show that $Z(\mathfrak{g})\subset\big\{X\in\mathfrak{g}\;|\;[X,Y]=0,\forall Y\in\mathfrak{g} \big\}$, my problem is that, when are they equal?

One can show the following:

Let $G$ be a connected Lie group. Then $Z(\operatorname{Lie}G) = \operatorname{Lie}Z(G)$.

Here, $\operatorname{Lie}$ denotes the functor from Lie groups to Lie algebras, i.e. $\operatorname{Lie}G$ is the Lie algebra of $G$.

There is a nice corollary:

Let $G$ be a connected Lie group. Then $G$ is Abelian if and only if $\operatorname{Lie}G$ is.

To prove the statement, we'll need the following lemma:

Let $G$ be a connected Lie group. Then $Z(G) = \operatorname{ker}(Ad:G \rightarrow GL(\operatorname{Lie}G))$

Proof of the lemma:

"$\subset$": This follows immediately from the fact that conjugation by an element that lies in the center is the identity on $G$, in particular its differential is just $\operatorname{id}_{\operatorname{Lie}G}$.

"$\supset$": Let $g$ be in the kernel, i.e. $(\alpha_g)_* \equiv \operatorname{Ad}(g) = \operatorname{id}_{\operatorname{Lie}G}$, where $\alpha_g$ denotes conjugation by g. But the functor Lie is faithful on the subcategory of connected Lie groups (*), so since $(\alpha_g)_* = \operatorname{id}_{\operatorname{Lie}G} = (\operatorname{id}_G)_*$, it follows $\alpha_g = \operatorname{id}_G$, thus $g \in Z(G)$.

This proves the lemma. In particular, since the kernel is a Lie subgroup of $G$, this shows that $Z(G)$ is a Lie subgroup, as well, and thus a Lie group, so the notion of $\operatorname{Lie}Z(G)$ in the original claim is in fact well-defined.

Proof of the original claim:

Since $Z(G)$ is a Lie subgroup of $G$, we can consider $\operatorname{Lie}Z(G) \subset \operatorname{Lie}G$ to be a subalgebra in the canonical way and $\exp_{Z(G)} \equiv \exp_G|_{Z(G)}$ (which we'll just denote by $\exp$ in the following).

"$\subset$": Let $X \in Z(\operatorname{Lie}G)$, i.e. $\operatorname{ad}X = 0$. If we find a curve $\gamma$ in $Z(G)$ whose derivative is $X$ we're done. The somewhat obvious idea is $\gamma(t) := \exp(tX)$ which has derivative $X$. So it remains to show that indeed $\gamma(t) \in Z(G)$. But $\operatorname{Ad}(\gamma(t)) = \operatorname{Ad}(\exp(tX)) = \exp_{GL(\operatorname{Lie}G)}(\operatorname{ad}(tX))$ by a commutative diagram which, in turn, equals $\exp_{GL(\operatorname{Lie}G)}(0) = \operatorname{id}_{GL(\operatorname{Lie}G)}$ and the claim follows by the lemma.

"$\supset$": Let $X \in \operatorname{Lie}Z(G)$, in particular $\exp(tX) \in Z(G)\; \forall t$. We have to show that $\operatorname{ad}X = 0$. Now, using commutative diagrams one can show in a straightforward way that $\forall x, y \in \operatorname{Lie}G$:

$$\exp x · \exp y · (\exp x)^{-1} = \exp(e^{\operatorname{ad}x}(y))$$

Here, $e \equiv \exp_{GL(\operatorname{Lie}G)}$ is the matrix exponential. We apply this identity in the following way: Let $Y \in \operatorname{Lie}G$ and let $U$ be a neighborhood of $0 \in \operatorname{Lie}G$ s.t. $\exp|U: U \rightarrow \exp U$ is a diffeomorphism. Pick $s, t \in \mathbb{K}, s,t \neq 0$ small enough s.t. $sX, tY, e^{\operatorname{ad}(sX)}(tY) \in U$. Then plugging in $x := sX, y := tY$ above and using $\exp(sX) \in Z(G)$ results in:

$$\exp(tY) = \exp(e^{\operatorname{ad}(sX)}(tY))\,,$$

so by injectivity of $\exp$ on $U$ (cancel $t$ using linearity):

$$Y = e^{\operatorname{ad}(sX)}(Y)$$

Since $Y$ was arbitrary, this implies $e^{\operatorname{ad}(sX)} = \operatorname{id}_{\operatorname{Lie}G}$ for all $s$ small enough. By choosing $s$ even smaller (if necessary), we achieve that $\operatorname{ad}(sX)$ is in a neighborhood of $0 \in \operatorname{gl}(\operatorname{Lie}G)$ where $e$ is injective as well and we obtain $\operatorname{ad}(sX) = 0$, implying the claim.

Proof of the corollary:

Let $G$ be Abelian. Then $Z(G) = G$, so by the above we have $Z(\operatorname{Lie}G) = \operatorname{Lie}G$, proving that $\operatorname{Lie}G$ is Abelian.

Let $\operatorname{Lie}G$ be Abelian, i.e. $\operatorname{Ad}_* = \operatorname{ad}: \operatorname{Lie}G \rightarrow \operatorname{gl}(\operatorname{Lie}G)$ is the zero map. But the map $G \rightarrow \operatorname{GL}(\operatorname{Lie}G), g \mapsto \operatorname{id}_{\operatorname{Lie}G}$ has differential $0$ as well, so once again by the faithfulness of the functor Lie we have: $\operatorname{Ad}(g) = \operatorname{id}_{\operatorname{Lie}G}$, i.e. $g \in Z(G)$, so $G$ is Abelian.

(*) The functor Lie is faithful on the category of connected Lie groups:

Let $G, H$ be two Lie groups, $G$ connected, and $f_{1,2}: G \rightarrow H$ two morphisms with $f_{1*} = f_{2*}$. Then $f_1 = f_2$.

Sketch of proof:

1. Pick an open neighborhood $U$ of $0 \in \operatorname{Lie}G$ s.t. the exponential map maps $U$ diffeomorphically to an open neighborhood $V := \exp{U} \subset G$ of $e \in G$.
2. Show that $f_1|_V = f_2|V$. (Use the standard commutative diagram involving $\exp_G, \exp_H$, $f_{1,2}$ and $f_{1,2*}$.)
3. Since $G$ is connected, it is generated by the elements in $V$, i.e. $G = \{g_1 · … g_n | n \in \mathbb{N}, g_1, …, g_n \in V \cap V^{-1}\}$. To see this, show that the right-hand side is an open subgroup of $G$, thus a closed subgroup, so it equals $G$ by connectedness.
4. Use 3) to extend the statement $f_1|_V = f_2|V$ from 2) to all of $G$.

I don't see the easy way to do this (I hope there is one) but

1) you can reduce the problem to the case of simply connected Lie group (because not simply connected Lie groups are factors of simply connected by some discrete subgroup of the center)

2) For simply connected groups one can use BCH formula to show, that the exponent of the element of the center lies in the center of the group.

This implies, that $\dim Z(G) \geq N$, where $N$ is the dimension of the center of Lie algebra. But you already have the reverse inequality.