Why is $\tan(x)$ a function?

The set $X$ in your definition is the domain of the function. The domain of $\tan(x)$ is typically taken to be

$$ X=\bigcup_{k\in\Bbb{Z}} \left(-\frac{\pi}{2}+k\pi,\frac{\pi}{2}+k\pi\right) $$

Thus $\pi/2\notin X$, and so don't need to assign a value to $\tan(\pi/2)$ (or for any $\pi/2+k\pi,k\in\Bbb{Z}$ for that matter).


When you say $f$ is a function, you should specify its domain (and codomain, but that's not really the issue here). If the domain is not specified, we take it to be the largest set on which the expression is defined. As you've pointed out $\tan$ is not defined at $\frac{\pi}{2}$ (so you should not even write $\tan\frac{\pi}{2}$ as this means the value of the function $\tan$ at the point $\frac{\pi}{2}$). Furthermore, $\tan$ is undefined at $\frac{\pi}{2} + k\pi$ for every integer $k$. Therefore, the largest set on which $\tan$ is defined is $\mathbb{R}\setminus\{\frac{\pi}{2}+k\pi\mid k \in \mathbb{Z}\}$; this is the domain of $\tan$ if the domain is unspecified.