I will try to answer this question and the linked question "in one" since they are related.
Integration by substitution becomes a bit subtle when you want to replace $x$ with something else. Whenever you have a substitution of the form $x=g(u)$, you need to ensure $g$ is a bijection. In particular, the image of $g$ needs to be the domain of the integrand (or, at least, a superset of it). Hence if $x=\sec u$, we want $u \in [0, \pi]$. This is convention, of course; any branch will do so long as it's consistently used. The inverse now is
$\sec u = x \Longleftrightarrow \cos u = \frac{1}{x} \Longleftrightarrow u = \arccos \frac{1}{x}$. The biconditional is justified because $u \in [0, \pi]$. There is no ambiguity. Now,
$$\frac{du}{dx} =\frac{1}{|x| \sqrt{x^2 - 1}} $$ or $dx = |x| \sqrt{x^2 - 1} \ du =|\sec u \tan u| \ du = \sec u \tan u \ du$. The removal of the absolute value sign is justified because $u \mapsto \sec u \tan u$ is $\geq 0$ for all $u \in [0, \pi]$.
This is precisely the same thing we get when we more "sloppily" differentiate with respect to $u$ with $x = \sec u$.
Now, let's integrate your integral
$$\int \frac{dx}{x \sqrt{x^2 - 1}} $$ from scratch. Let $x=\sec u$. Then $dx = \sec u \tan u \ du$. This yields
$$\int \text{sgn}(\tan u) \ du = \text{sgn}(\tan u) |\sec^{-1} x| + C =
\begin{cases}
\sec^{-1}(x) + C_1 & x \geq 1 \\
-\sec^{-1}(x) + C_2, & x \leq -1
\end{cases}$$
For your final answer, you can replace $\sec^{-1}$ with $\frac{\pi}{2} - \csc^{-1}$ and consolidate the constants; this should address the doubt raised in the other question.
Working with disconnected domains and non-injective functions, in this context, it is a bit tricky to rigorously justify some stuff, but it all works out in the end.