Scotland's cash-strapped councils have been forced to spend hundreds of millions of pounds on hotel rooms for homeless people.