So why is it a function, even though for example $x = 8$; you'll have $y = +2$ and $y = -2$. It'll fail the vertical line test. But every textbook considers it as a function. Did I misunderstand something?
Edit: Wait how come $y = \sqrt{4 - x^2}$ is a function too when it can be transformed into $$ y = \sqrt{4-x^2} $$ $$ y^2 = 4- x^2$$ $$ x^2 + y^2 = 4 $$ $$ \frac{x^2}{4} + \frac{y^2}{4} = 1$$
which is an equation of a circle and not a function
Consider these two questions:
These questions are related, but they are not the same.
For the first question, there are two answers: $\pm 2$, since both of these numbers squared will give you $4$.
The second asks: "what nonnegative number, when squared, gives you $4$?" The answer to that is $2$ (and not $-2$). In general for a nonnegative real number $x$, its square root, $\sqrt{x}$ is defined to be the nonnegative solution $y$ to $y^2 = x$.
Thus, $\sqrt{8-4} \neq -2$, so the graph $y=\sqrt{x-4}$ contains the point $(x,y) = (8,2)$ but not $(x, y) = (8, -2)$. In general there is at most one answer to the question "evaluate $\sqrt{x-4}$," so the graph does indeed pass the vertical line test. (You can see a sketch of the graph on Wolfram Alpha.)
(Things get more interesting when we try to define a square root of a complex number!)
Edit (in response to follow up question about $y = \sqrt{4-x^2}$): Consider the graphs of $y^2 = x$ and $y = \sqrt{x}$. Based on the discussion above, they are not the same graph. The graph $y^2 = x$ "transforms" into $y = \pm \sqrt{x}$, which is not a function.