Basicity of nitrogen heterocyclic compounds
Nitrogen inversion is not relevant to this discussion. A faster rate of inversion does not correspond to a greater delocalisation in the electronic structure, as lone pair inversion is not equivalent to resonance. The lone pair does not exist as a delocalised smear; it exists in two different localised forms.



The PDF on nitrogen inversion in the comments does not even bring up the topic of basicity, and quite rightly so.

Inductive effects explain why morpholine 2 is less basic, and resonance effects explain why pyrrolidone 4 is even less basic. However, since the pKaH's of piperidine 1 and pyrrolidine 3 are so similar (11.22 and 11.27 respectively), I think it is pointless to try and qualitatively rationalise a difference in their basicities. It is like trying to explain why the temperature in Spain one day is 11.22 °C and the temperature the next day is 11.27 °C. The relative basicity could well be different if you switch the solvent, which would invalidate any reasoning based on - for example - s-orbital character of the nitrogen lone pair, which I think is the only plausible qualitative argument here.

Simply looking at the data, though, the order you want is 4 &lt; 2 &lt; 1 &lt; 3.