knzhou has explicitly showed in his post how the form $\displaystyle\int r^2~\mathrm dm$ came to picture. So, I'll be not writing the same thing again. Nevertheless, since, OP is interested in the "logical development" of the idea, I deem it worthy to add a brief discussion on moment of inertia as a second-rank tensor in a more general case so that OP might get a view of the whole topic in short.
Introduction:
The angular momentum $\mathbf L$ of a rigid body with respect to a certain stationary point is expressed as:
$$\begin{align}\mathbf L &= \sum_i \mathbf r_i\times (m_i\mathbf v_i)\\ & =\sum_i \mathbf r_i \times m_i (\boldsymbol \omega \times \mathbf r_i)\end{align}$$ where $\mathbf r_i$ is the distance of the $i$ th particle from the fixed point.
Using the identity $\mathbf A\times \mathbf B\times \mathbf C= \mathbf B(\mathbf A\cdot \mathbf C)- \mathbf C(\mathbf A\cdot \mathbf B),$ we get $$\mathbf L = \sum_i \left[m_i~\boldsymbol \omega r_i^2 - m_i \mathbf r_i(\mathbf r_i\cdot \boldsymbol \omega)\right]\tag I$$
From $\rm (I)$ we get the $x$ component of $\mathbf L$ as
$$L_x = \sum_i\left[ m_i(r_i^2 -x_i^2)~\omega_x - m_ix_iy_i~\omega_y- m_ix_iz_i~\omega_z\right]$$
So, $L_z$ is a linear function each component of angular velocity.
Thus, $\mathbf L$ is linearly transformed from $\boldsymbol \omega\,.$
This can be expressed as $$\mathbf L = \mathsf I\boldsymbol\omega\tag{II}$$
where $\sf I$ is an operator which linearly transforms $\boldsymbol\omega$ to $\mathbf L\,.$ That is,
$$L_i = \sum_j ~I_{ij}~\omega_j$$
$$\therefore ~~~~~~~~~ \mathsf I \equiv \begin{bmatrix}I_{xx} & I_{xy}& I_{xz}\\ I_{yx}& I_{yy}& I_{yz}\\ I_{zx}& I_{zy}& I_{zz} \end{bmatrix} $$ where $$I_{ij} = \sum_ i m_i (r_i^2 ~\delta_{ij} - r_ir_j)\tag{III}$$ and $\mathbf L$ and $\boldsymbol\omega$ are column matrices.
Ellipsoid of Inertia:
From $\rm(III),$ it can be concluded that $I_{xy} = I_{yx};$ this means $\sf I$ is a symmetric matrix.
Any symmetric linear operator can be expressed in a unique diagonal form (the diagonal elements are unique but the order of the elements may be different) by orthogonal transformation of coordinates. The corresponding principle axes will be unique and orthogonal.
Now, kinetic energy $\textrm{KE}$ of the rigid body is $$\begin{align}\textrm{KE}&=\frac12 \sum_i m_i (\boldsymbol \omega \times\mathbf r_i)\cdot (\boldsymbol \omega \times\mathbf r_i)\\ &=\frac12\sum_i m_i \boldsymbol\omega\cdot (\mathbf r_i\times (\boldsymbol \omega \times\mathbf r_i))\\&= \frac12\boldsymbol\omega\cdot \mathbf L\\ &= \frac12 \boldsymbol\omega\cdot \mathsf I\boldsymbol \omega~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(\textrm{using}~\mathrm{II})\end{align}$$ which on expanding gives $$\begin{align}T &=\frac12( I_{xx}\omega_x^2 + I_{yy}\omega_y^2 + I_{zz}\omega_z^2) + \frac12\sum_i\sum_j(I_{ij}\omega_i\omega_j) \\ &= \frac12\sum_{i}I_{ii}~\omega_i^2 + (I_{xy}\omega_x\omega_y + I_{yz}\omega_y\omega_z + I_{zx}\omega_z\omega_x)~~~~~~~~~~~~~(I_{xy}= I_{yx}) \end{align}\,.$$
Now, when $x,y,z$ are the principle axes, then $$T=\frac12( I_{xx}\omega_x^2 + I_{yy}\omega_y^2 + I_{zz}\omega_z^2)\,. $$
The quadratic equation implies that the locus of angular velocities for which $\mathrm{KE} $ is constant must be an ellipsoid since energy is always positive.
This means all the off-diagonal elements of $\mathsf I$ will be zero and $\mathbf L \parallel\boldsymbol{\omega}\,.$
So, in principle axes, only the diagonal coefficients of moment of inertia are non-zero viz. $$L_i = I_{ii}\omega_i^2\,.$$
References:
$\bullet$ Classical Mechanics by Goldstein.