We have $$\int_{-1}^{1} \dfrac{1}{x} \, dx$$ as undefined and then we have $$\int^1_{-1} f(x)\delta(x) = f(0)$$
assuming $f(x)$ is continuous everywhere and $$\delta(x) = \begin{cases} 0 & x\ne 0, \\ \infty & x = 0. \end{cases}$$
In both cases the integrand is infinite for $x = 0$, then why second integral is not undefined?
As mentioned in the comments, $\delta$ is not a function in the classical sense, but a distribution. For simplification you can think of it as a definition that $\int f(x)\delta(x)\,dx = f(0)$.
But be careful because in the if you define a classical function $$\hat \delta(x) = \begin{cases} 0 & x\ne 0 \\ \infty & x = 0{}\end{cases}$$ as a classical function then for all integrable functions $f$ we get: $\int f(x)\hat\delta(x)\,dx = 0$ since $\hat\delta$ is zero almost everywhere and therefore $f\cdot\hat\delta$ is zero almost everywhere.
To further understand why you could say that this equation is kind of valid for the dirac distribution, you need a fundamental understanding of measure theory and functional analysis.
If you have a basic background in measure theory, you can understand the delta distribution as the extended radon-nikodym-derivative of the dirac measure and the lebesgue measure.