An appeals court in Brescia, northern Italy, had sentenced the man to three months and ten days in jail after he allegedly snuck into a private home in a Lombard town.
The man had entered a house in Desenzano del Garda on the shores of Lake Garda in late November the previous year.
Initially, he had been accused of burglary, however the charge was downgraded to trespassing (violazione di domicilio) by the appeals court in 2015.
But in the ruling published on Thursday, supreme court judges quashed the ruling, saying the man should not be punished due to his "particular circumstances of poverty and exclusion".
Judges also noted that the man's motivation for the act had been simply "to find a place to stay for the night" and therefore could not be classed as acting with criminal intention.
In 2016, a similar case saw the judges acquit a man of stealing food from a supermarket on the grounds that he "acted out of necessity" as he couldn't afford to feed himself.
READ ALSO: Italy's top court says it's not a crime if the hungry poor steal food