Second moment of area

I am having trouble understanding the term. How come that calculating the integral of the product of multiplying the Area differential by (distance)^2 determines the stiffness of the beam or so and its resistance to bending? does it have anything to do with the first moment of area and torque?

I can easily explain the stress-moment relationship in beams. I am sure you are familiar with it, and the area moment $I$ comes out naturally.

$$\sigma_{max} = \frac{M y_{max}}{I}$$

Take a section of the beam with internal moment $M$. This moment has to be supported by the stress distribution internally. For straight beams, there is a neutral axis in the middle of the beam, and the stress values vary linearly from the distance $y$ to the neutral axis $$\sigma(y) = k y$$ At the limit $\sigma_{max} = k y_{max}$ or $$k = \frac{\sigma_{max}}{y_{max}}$$

Take a cross section and integrate slices along the height $y =y_{min} \ldots y_{max}$ each with a thickness $b(y)$.

The area if the section is thus

$$A = \int {\rm d} A = \int \limits_{y_{min}}^{y_{max}} b(y)\,{\rm d}y$$

The moment is found by the product if the infinitesimal tension ${\rm d}F = \sigma(y) \,{\rm d}A$ and the height $y$.

$$M =\int y {\rm d}F = \int y \sigma {\rm d} A = \int \limits_{y_{min}}^{y_{max}}y \sigma b(y)\,{\rm d}y = \int \limits_{y_{min}}^{y_{max}}k y^2 b(y)\,{\rm d}y$$

or

$$k = \frac{M}{\int \limits_{y_{min}}^{y_{max}} y^2 b(y)\,{\rm d}y}$$

The denominator we call the area moment because it contains any information from the geometry of the problem

$$\boxed{I = \int \limits_{y_{min}}^{y_{max}} y^2 b(y)\,{\rm d}y}$$

To answer your question on why the $y^2$ term in the integral, one of the $y$ comes from the linearity of the stress distribution $\sigma = k y$ and the other $y$ from the moment arm calculation ${\rm d}M = y {\rm d}F$.