Very briefly, my understanding of the initial motivations for studying $L^p$ spaces included interest in the $\ell_2$ space, due to relationships with quadratic forms that arose from searching for coefficients of Fourier series.
Then I believe separately the study of heat equations led to integral equations, and Hilbert eventually found that being in $L^2$ was sufficient for certain solutions to exist. Hilbert wouldn't have put it that way at the time, but as a rough and very fast description, I think it does the job.
In the end, it seems like all the motivations could be traced back to physics problems giving rise to certain mathematical problems, which the mathematicians then took interest in.
I wonder if anyone knows a similar story about what people were working on which led to the study of linear functionals and Riesz representation. For instance, I guess when people understood $L^2$ well enough they could be guaranteed of the existence of solutions to certain differential equations that they wanted to understand. So analogous with that, when they found the Riesz representation theorem, did that then deliver on something which had previously motivated the project?