A homeless man is fighting his case by invoking New York’s “castle doctrine,” which gives people the right to defend their dwellings. Each night, Joseph Matos builds his home on the East Side by placing several cardboard boxes on the ground for cushioning and then linking together a half dozen others so he can fit inside to sleep. One night in October 2018, he said, he was jolted from his slumber by a thud, followed by another. Startled, he leapt outside and grabbed a knife. A college student, walking by with a friend, had kicked Mr. Matos’s box because he...