Scotland’s most senior judge believes the country’s prison system is under pressure because too many people are being jailed.