A damning report has concluded that children trapped in Scotland's homelessness system are being failed, with many exposed to violence and unhealthy conditions.