4 of us are playing
P1: 2 cities and 3 activated knights
P2: 2 cities and 1 activated knight
P3: 2 cities and 0 activated knight
P4: 2 cities and 0 activated knight
When barbarian attack, would player P2 also lose a city?
No, only the player(s) who contributed the least will lose a city. Players 3 and 4 are tied for the least, so they each lose one.
If the barbarians are stronger, they are victorious! If the barbarians win the battle, they pillage one or more cities. Pillaged cities are reduced to settlements (replace the city piece with a settlement). The barbarians pillage one city belonging to the player who had the lowest total strength of active knights when the barbarians attacked. Any player who contributed no knights are automatically considered to have the lowest total strength of active knights. If various players tie for having the lowest total strength of active knights, each of those players loses 1 of their own cities.
https://www.catan.com/sites/default/files/2021-06/catan_c_k_2020_rule_book_200708.pdf