Thousands of Scots were left homeless last year after the government slashed its affordable housing spending.