The free theory you quote is on the worldsheet and does not imply in a free theory on the target space. Also you don't have just $D$ free massless scalars. Before gauge-fixing you also have the two-dimensional metric as a degree of freedom. In that case when defining the functional integral you must take both into account
$$Z[0]=\int \mathfrak{D}h \mathfrak{D}X e^{-S_{\rm P}[h,X]}\tag{1}.$$
The gauge invariance of $S_{\rm P}[h,X]$ demands you to use the Faddeev-Popov procedure to properly define (1). When doing so you are going to gauge fix at the expense of introducing ghost fields as usual and in the process discard the (infinite) volume of the gauge group ${\cal G}={\rm Diff\times Weyl}$.
Now observe that you integrate over the metric. In a given topology for the worldsheet some metrics can be defined and other ones can't. This means that in practice the space of metrics is sliced by worldsheet topology and the integral includes a sum over topologies of the worldsheet as well. In a given topology you may or may not be able to completely fix the metric. Indeed with the topology of a sphere you can gauge fix the metric away and set it to $\hat{h}_{ab}=\delta_{ab}$. On a torus topology you already can't do that and you will also have one integral over metrics on that particular topology (which turns out to be an integral over a finite-dimensional space, see Polchinski's Chapter 5). So as you see the worldsheet does not have a fixed topology because you must integrate over the metric in the path integral.
In the end you have more than just $D$ free massless scalars. There is this remaining integral over metrics when the topology does not allow you to completely gauge fix it away and there are also the ghost fields.
For a perhaps more detailed discussion of the passage you quote I suggest you study in detail Polchinski's Chapter 3. In particular section 3.5 - "Scattering amplitudes". Polchinski's Chapter 5 is also good to understand the sum over topologies that I have briefly mentioned. Also see Tong's notes Chapter 6.