When does $(e^a)^b = e^{ab}$ hold?

By definition, $$ \exp(A)^B = \exp(B \ln(\exp(A))) = \exp(B (A + 2 \pi i n)) = \exp(AB) \exp(2\pi i n B)$$ where $n$ is an integer. Different values of $n$ determine which branch of the logarithm (and thus of the power) is being used. In particular, $\exp(2 \pi i n B) = 1$ if and only if $nB$ is an integer.

In particular, suppose you're using the principal branch, i.e. $-\pi < \text{Im}(\log(z)) \le \pi$ for all $z$. If $A = x + i y$, $\ln(\exp(A)) = x + i y + 2 \pi i n$ where $n$ is chosen so that $-\pi < y + 2 \pi n \le \pi$. In particular $n = 0$ if and only if $-\pi < \text{Im} A \le \pi$. For such $A$, your identity is true for all complex $B$. If $\text{Im} A$ is not in that interval, $n \ne 0$ and your identity is only true for a discrete set of values of $B$.


Let's try to see what $(e^a)^b$ means first:

Well, $(e^a)^b= e^{b \cdot \ln(e^a)}$, by definition. Now, if only it were true that $\ln(e^a)=a$ then we would be happy, and $(e^a)^b$ would be our familiar $e^{ab}$.

Now, let $a=x+iy$ where $x,y$ are reals.

Then, $e^a=e^x \cdot e^{iy}$. What is $\ln(e^a)$ then? It should be $\ln(e^x)+\ln(e^{iy})$. There are no problems with $\ln(e^x)$, as $x$ is real.

However, lot of care must be taken while dealing with complex logs.For example see here. A brief reason is because $e^{iy}=e^{i(2\pi+y)}$, we are in a spot of bother. (This point is very well taken in your question).

So, there is no problem with the formula $(e^a)^b=e^{ab}$ if $a$ is real. The troubles begin when $a$ is complex, for the reasons mentioned above.

Thuus the answer to your question is that the formula hols for real $a$ and any $b \in \mathbb{C}$.