Suppose we are asked to show that if $X$ is a random variable with density ($\forall x \in \mathbb{R}$) $$f_X(x) = \frac{1}{\pi(1+x^2)} ,$$ then $Y = \frac{1}{X}$ has the same distribution as $X$ ($Y \sim X$). I am well aware of the approach to take here: indeed, we can compute the density of $Y$ by first calculating the cumulative distribution of $Y$, $F_Y$, in terms of the cumulative distribution of $X$, $F_X$.
$$\begin{align} F_Y(y) = \mathbb{P}(Y \leq y) &= \mathbb{P}\left(\frac{1}{X} \leq y\right) \\ &=^{[\text{if } y \neq 0]} \mathbb{P}\left(X \geq \frac{1}{y}\right) \\ &= 1 - \mathbb{P}\left(X \leq \frac{1}{y}\right) \\ &= 1 - F_X \left(\frac{1}{y}\right). \end{align}$$
Continuing with the computation, we can take the derivative with respect to $y$ to obtain the density of $Y$. To this end, we have
$$f_Y(y) = \frac{\text{d}}{\text{d}y}F_Y(y) = -f_X \left(\frac{1}{y}\right) \cdot \left(-\frac{1}{y^2}\right) = \frac{1}{y^2} f_X \left(\frac{1}{y}\right) = \frac{1}{y^2}\frac{1}{\pi\left(1 + \frac{1}{y^2}\right)} = \frac{1}{\pi(1+y^2)},$$ for all $y \neq 0.$ My question is in regards to this last restriction which comes from the third equality in the first set of equations. The distributions surely cannot be the same if one holds for all $x$ and the other holds for all $y \neq 0$. Am I missing something here? It's a small but important detail for me. I appreciate any input, thank you.
Technically, density is defined through integration (rather than differentiation). Given a distribution function $F$, any non-negative Lebesgue measurable function $f$ such that
$$F(x) = \int_{-\infty}^x f(t) \, dt, x \in \mathbb{R} \tag{1}$$
is called a density function of $F$ (with respect to Lebesgue measure). For a more general definition under a measure context, see page $213$ of Probability and Measure by Patrick Billingsley.
Therefore, technically speaking, given any distribution function $F$, its density is an equivalent class of functions: as long as $f_1$ and $f_2$ agree outside a set of Lebesgue measure $0$, and both of them satisfy $(1)$ and non-negativity, both of them can be referred to as density of $F$.
Regarding to your case, what really matters is whether
$$\int_{-\infty}^z f_X(z) \, dz = \int_{-\infty}^z f_Y(z) \, dz.$$
If the above equation can be verified, then $X$ and $Y$ will have the same distribution.