There's two (ultimately related) answers.
For the first answer, just forget about $\hbar$ (but say $c=1$), we are doing a classical relativistic field theory.
The first is that you can consider the field profile around a static, spherically symmetric source of mass $M$ (you need to add a coupling to the action of the form $g\, \phi J$, where $J$ is an external source, to do this).
So we write the static spherically symmetric source as
$$ J=J_0 \delta^3(r) .$$
(if you don't like delta functions you can make it a top hat or a shell and you will find the same conclusions below, this kind of manipulation should be familiar from E/M classes)
You can work out the equations of motion for $\phi$, you will find
$$\nabla^2\phi + m^2 \phi = g J_0 \delta^3(r).$$
This looks exactly like Poisson's equation, except with this extra $m^2$ term (which I haven't called a mass yet). If you solve it (say using green's functions, or you could just make an explicit ansatz) you will find the solution is
$$\phi = g J_0 \frac{e^{-m r}}{4\pi r} .$$
This is the famous yukawa potential with mass $m$. It describes a force with a range $m^{-1}$, which you may have heard before is the smoking gun for force carrying particle having mass (the weak interactions are so weak at human distances because $m$ is so big)
Now at this point you are still justified in asking why we are calling this quantity $m$, which in the classical analysis above is just an inverse length, a mass.
The second answer addresses this more directly. It comes when we quantize the theory. This is discussed in great detail in many qft textbooks, but the gist is relatively simple. At this point I will say $\hbar=1$, if you really want to keep track of the $\hbar$ dependence you can get it back by dimensional analysis.
If you take the equations of motion for the above system without the source (note we are no longer working with static systems):
$$-\partial_t^2\phi + \nabla^2 \phi + m^2 \phi = 0.$$
and go to fourier space
$$\tilde{\phi}(\vec{k},t)\equiv\int\frac{d^3 k}{(2\pi)^3}e^{i\vec{k}\cdot\vec{x}}\phi({\vec{x},t})$$
then you will find the equations of motion are
$$-\partial_t^2 \tilde{\phi} +\vec{k}^2\tilde{\phi} + m^2\tilde{\phi}=0$$
This is just a set of harmonic oscillators, labeled by $\vec{k}$ with frequency
$$\omega^2=\vec{k}^2+m^2$$
We can think of $\tilde{\phi}(\vec{k},t)$ for a single value of $k$ as being a single quantum variable obeying a harmonic oscillator equation, so there when we quantize these variables we will have one wave function for each value of $\vec{k}$, each of which obeys a schrodinger equation for a harmonic oscillator with the above frequency. Each harmonic oscillator will be quantized and have discrete energy levels. These energy levels are what we call 'particles'. The idea is that for a given momentum, the field $\phi$ can only have certain values of energy, and the interpretation is that these quantized wiggles in $\phi$, or in other words discrete packets of energy, are particles.
Now we remember we are doing quantum mechanics, and we are supposed to identify frequency with energy and momentum with wavelength, using
$$E=\omega,\quad \vec{p}=\vec{k}.$$
So we are describing a system with a relationship between energy and momentum given by
$$E^2=\vec{p}^2+m^2.$$
This is einstein's famous formula, and now we see that the parameter $m$ appears in exactly the place the mass of a particle would appear. It is the energy that a particle has when it has $0$ momentum. So we identify the particle like excitations we discovered above with particles of mass $m$.
However I emphasize that there are many, many, many other treatments of this and other ways of looking at it.
A good question would be, what does a particle mean if you don't have a free theory and don't get a harmonic oscillator equation above?