Suppose we have that $X_1, \ldots, X_n \sim N(\mu, \sigma^2)$ where $\sigma^2$ is known. If we wanted to test the hypothesis of:
$$ H_0: \mu = \mu_0 \ \ \text{and} \ \ H_1: \mu \neq \mu_0 $$
a lot of books just jump directly to using a z-score based test statistic of:
$$ Z = \frac{\bar{X}-\mu}{\sigma/\sqrt{n}} \sim N(0,1) $$
However, I do not understand why or how they jump to this statistic aside from the fact it appears the normal distribution is easy to calculate from.
My question is, my understanding is that formally, we can choose any test statistic $T(X)$ such that:
$$ P(T(X) \in R\mid H_0) = \alpha $$
where $R$ is a rejection region to be found and $\alpha$ the significance level.
I am wondering how one can formally derive the $Z$ score approach above? Thanks.