Councils across Scotland have broken the law that ensures the homeless including children and pregnant mothers are given some kind of roof over their heads nearly 19,000 times over six years.