So, duh moment. Did you know that the noun fence–like, you know, the thing around your yard–is from defense? Yeah. Duh. I’d never paused to consider that, perhaps because the spelling has ended up different, but there you go! It has been a shortening of defense with the same meaning since the 14th century. Then sense of that enclosure followed in the 15th century.
It had a similar verb meaning at the same times too, with the “to sword-fight” way of defending oneself arising in the 1590s.
But the reason I looked it up was for the meaning that has a fence being someone who buys and sells stolen goods…and to fence being to sell those stolen goods. I expected it to be a pretty modern use, but no! As the verb, it’s been around since 1610, and it was then applied to the person doing it right around 1700–all from the idea that it’s accomplished under “the defense of secrecy.”