Why is $\tan(x)$ a function? A function $f:X\rightarrow Y$ maps each $x\in X$ to some $y \in Y$. So consider $\tan{\frac{\pi}{2}}$ for which $\tan(x)$ is undefined, so in this case, $\tan(x)$ does not map to an element of its range. This conflicts with my understanding of what a function is. Why do we still consider $\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).
Actually that is the definition of a continuous function. The definition for a function is that for all inputs there is exactly one output. In a non-continuous function, when the input doesn't map to anything, it is not in the domain. So if f(pi/2) is undefined, pi/2 is not in the domain and therefore not an input.