@kushal I don't know for certain, but I think what the cops may refer to as a reason why they would be allowed to do that is so called "inre utlänningskontroll", see https://polisen.se/om-polisen/polisens-arbete/granspolisen/fragor-och-svar-om-inre-utlanningskontroller/
The rules seem vague regarding what reasons can justify that. Cops can ask a person for ID, but it does not seem logical to me because is you are a Swedish citizen then you are under no obligation to carry an ID, so a person who gets asked could just claim to be a Swedish citizen not carrying any ID.
@kushal I don't like those rules, it feels too much like arbitrary harassment of people who are "foreign-looking".
Unfortunately the current Swedish government is pushing to extend such things:
"I prop. föreslår regeringen [...] möjlighet för myndigheterna att vid en inre utlänningskontroll kroppsvisitera en utlänning för att söka efter pass eller andra identitetshandlingar och en möjlighet att omhänderta sådana handlingar"
They don't care much for civil liberties 😕