Prisoners released from jail back into society should be given more help to address the challenges they face, the chief inspector of prisons has said.
David Strang highlighted the case of a prisoner at HMP Kilmarnock who shoplifted in the hope he would be caught and returned to jail.
The man had been living in a tent for eight weeks following his release.
The Scottish Prison Service said significant investment had been made in "throughcare" for inmates.
Mr Strang said inspectors had spoken to the man caught shoplifting, who told them no accommodation had been available to him after he was released from prison.
The former inmate wanted to return to prison because he believed it was the only way for him to access a dry bed, warmth and shelter.
Mr Strang acknowledged that returning to the community from prison was "challenging" and said many individuals needed more direct support than was always available to them.
He has called for all agencies involved in the reintegration of prisoners back into their communities to work collaboratively "in order to ensure the best possible outcomes".
Referring to the specific example of the prisoner, who had previously been at HMP Barlinnie, he said: "These are not the circumstances we want people leaving prison in 21st Century Scotland to have to face.
"However, it is not a situation that can be resolved by the prison service alone.
"This requires a dedicated and co-ordinated response by all those involved in supporting people in the criminal justice system and beyond."
The chief inspector was speaking as he launched his full report of an inspection of Kilmarnock prison in East Ayrshire, which was carried out in November.
He said it was "disappointing" there were no dedicated throughcare support officers at HMP Kilmarnock, adding that prisoners were denied levels of support available at other prisons in Scotland.
The prison, which can hold about 500 people, is one of two operated by private sector organisations on contract to the Scottish Prison Service (SPS).
The report concluded the institution was secure and well-ordered, with the majority of staff and prisoners saying they felt safe.
Inspectors graded the prison satisfactory or acceptable across all main criteria.
But they also noted the prison contract itself was seen by many as "a barrier to progress and a reason for inflexibility and resistance to change".
An SPS spokeswoman said: "SPS's significant investment in throughcare support officers means that those leaving custody are now supported in planning for their release at a much earlier stage in their sentence, in order to ensure that they have access to key services on release."
Welcoming the wider report, she said: "SPS also welcomes HMIP's comments that Kilmarnock is a safe prison, with a good range of educational and vocational opportunities available to those in our care.
"The report also notes that HMP Kilmarnock offers a well-considered range of purposeful activities to match the ability, preference and age of most prisoners."
She added that the SPS did not share the view the contract may inhibit the delivery of services to inmates at Kilmarnock.
A Scottish government spokeswoman said: "The inspection findings reflect our position, that public services must respond to the needs of people in the justice system, and particularly those being released from prison.
"Anybody presenting as homeless when they leave prison must be given support by the relevant local authority, but we recognise that housing service provision is complex.
"We are supporting ongoing work between justice and housing partners to develop a consistent and shared approach across the country."
Alison Watson, from Shelter Scotland, said the provision of stable, safe and affordable homes for former inmates was key to breaking the offending cycle.
"When in prison, people often lose their accommodation because of an inability to pay rent whilst serving their sentence or through a family break-up," she said.
"Many don't have a job to go back to upon release, making finding and maintaining a home very difficult.
"It doesn't need to be this way and with the right advice and support, ex-offenders can go on to lead successful lives and contribute a great deal to our society."