When I first learned this phrase I was in middle school. It relates to the common late medieval custom that serfs could, upon residing inside a city for a set time, often “a year and a day”, claim freedom from bondage. I always pictured myself as that serf, approaching the city walls with a sense of excitement.
It’s a simplification, of course. The conditions under which cities granted freedom to wandering peasants varied considerably from place to place and time to time. And there were limits to the freedoms granted, and to the extent to which a medieval chattel could “reinvent” himself as a free urbanite. But there was a core of truth to this.