BOSTON — A homeless man convicted of criminal trespassing for taking shelter in privately owned buildings during harsh winter weather won a new trial Thursday when the state’s highest court ruled that he should have been allowed to argue it was his only way to protect himself from the cold. The Supreme Judicial Court found that the judge at David Magadini’s trial was wrong to deny a request to instruct the jury on a so-called necessity defense.