I am solving this for particles distributed in a 2D space. First we know that the moment of inertia of a particle about an axis is given by
$$I=Mr^2$$
And we know that the axes passing through COM have the minimum moment of inertia. Our job is to find the slope of the axes with min Inertia, then we can use the slope point form to find the equation of the required axis :
$$y - y_0 = m ( x - x_0 )$$
(Where m is the slope of the line and $(x_0, y_0)$ is the point through which it passes)
Now let us consider the distribution of masses, the coordinate of COM is given by:
$$
x_{cm} = \frac{1}{M} \sum_i M_i x_i
$$
$$
y_{cm} = \frac{1}{M} \sum_i M_i y_i
$$
And now let us shift the origin to COM to make our calculations easy. If the original coordinate of mass $M_i$ was $(x_i, y_i)$ then the new shifted coordinates are:
\begin{align}
x_i' & = x_i - x_{cm} \\
y_i' & = y_i - y_{cm}
\end{align}
Hence the axis that we seek now passes to the new shifted origin $(x_0, y_0)$.
Now let the equation of the line be
$$y = mx$$
(as this line passes through origin, $c = 0$).
Then the distance $r_i$ of the $i$th particle from this line, is given by :
\begin{align}
r_i = \frac{|m x_i' -y_i'|}{\sqrt{1+m^2}}
\end{align}
Hence the total moment of Inertia of the system is :
\begin{align}
I = \sum M_i r_i^2
\end{align}
Now we can differentiate it with respect to $m$ (slope) and equate it to zero to find the minima:
$$
\frac{dI}{dm} = \sum \frac{2M_i(mx_i'-y_i)(x_i'+my_i)}{(1+m^2)^2}
$$
Equating it to zero gives :
$$
\sum M_i(mx_i'-y_i)(x_i'+my_i)=0
$$
Solving for m gives the following quadratic equation :
$$
\left(\sum M_i x_i'y_i'\right)m^2 + \left(\sum M_i (x_i'^2-y_i'^2)\right)m - \left(\sum M_i x_i'y_i'\right) = 0
$$
Note that the product of roots (that is slopes) is -1 i.e. this gives two two axes perpendicular to each other and one among them has minimum momentum and other has max about it (they can be found out by differentiating the above quadratic equation again)
Thus the the axis we seek, in the original coordinate system maybe be written as:
$$
y-y_{cm} = m(x-x_{cm}).
$$
where $m$ is the slope which corresponds to minimum inertia.