Resonance of lone pair of nitrogen in 4‐nitroaniline and piperidin‐2‐one
Considering that you're referring to the difference in the number of resonating structures, you're right in that aspect. 4‐Nitroaniline does have more resonating structures than piperidin‐2‐one. But in organic chemistry, you should be knowing that for a phenomenon to happen, there have to be several contributing factors.
While this includes the number of resonating structures as one, you have to take into consideration the other factors as well. And this includes the other factor you have mentioned in your answer — the position of the negative charge.
Since carbon is an atom which has an electronegativity of 2.55 (According to the Pauling scale), a negative charge on it would make it highly unstable, lowering the resonance energy, thus reducing the resonance stabilization in it. Nitrogen and oxygen have electronegativity of 3.04 and 3.44, respectively, thus a negative charge on those atoms would increase the resonance energy, thus increasing the resonance stabilization.