The measure theory was born from the need to formalize the idea of integration for Lebesgue.
In this context we need of the notion of measurable function for identify the class of function on which successively we could define the notion of integral.
In particular, the Lebesgue integral would generalize, in some sense, the Riemann integral.
The idea behind the formal construction of Lebesgue integral is well exemplified by the following image:

(from here let's limit ourselves to thinking only of non-negative functions for simplicity, and assuming that we know the definition of Lebesgue integral only for step function supported on measurable set)
So with Lebesgue's idea we fix a certain values $\{a_n\}, \hspace{0.2cm} a_n \in \mathbb{R^+}$ and we define $E_n=f^{-1}([0,a_n])$ and at the end we approximate the function with $f \approx \sum_n a_n \chi_{E_n}$
(Remark: This passage gives the idea but is not exactly rigorous, in fact the intersections of these steps would have to be removed, but for our discussion it is inessential)
At the end with a certain limit we Will find the rigorous definition, but is not necessary to explain for our discussion.
It is clear that in this construction it's crucial that $E_n$ had to be measurable sets, because only in these case we know how do the integral.
So the class of function on which we can define the Lebesgue integral construction is the collection of f such that $E_n=f^{-1}([0,a_n])$ is a measurable set $\forall a_n \in \mathbb{R^+}$. But, with the right small adjustments, this is essentially the definition of measurable function