The ruling says city officials cited no evidence that homeless shelters and other types of housing posed an immediate threat to public safety.