“If i have a friend staying in my shed can the cops tell him he cant live in there? Can the city?”
Most likely yes. Most cities have zoning ordinances and building codes which specify what types of buildings qualify as living units, and how many may be on a particular property. If the local ordinances in your area prohibit such a use, or if the shed is not considered a living unit (few sheds are), then it is very possible that the police or city officials could take action to stop this.