First, say Botticini and Eckstein, the exodus from farms to towns was probably not a response to discrimination. It's true that in the Middle Ages, Jews were often prohibited from owning land. But the transition to urban occupations and urban living occurred long before anybody ever thought of those restrictions. In the Muslim world, Jews faced no limits on occupation, land ownership, or anything else that might have been relevant to the choice of whether to farm. Moreover, a prohibition on land ownership is not a prohibition on farming—other groups facing similar restrictions (such as Samaritans) went right on working other people's land.
Nor, despite an influential thesis by the economic historian Simon Kuznets, can you explain the urbanization of the Jews as an internal attempt to forge and maintain a unique group identity. Samaritans and Christians maintained unique group identities without leaving the land. The Amish maintain a unique group identity to this day, and they've done it without giving up their farms.
So, what's different about the Jews? First, Botticini and Eckstein explain why other groups didn't leave the land. The temptation was certainly there: Skilled urban jobs have always paid better than farming, and that's been true since the time of Christ. But those jobs require literacy, which requires education—and for hundreds of years, education was so expensive that it proved a poor investment despite those higher wages. (Botticini and Eckstein have data on ancient teachers' salaries to back this up.) So, rational economic calculus dictated that pretty much everyone should have stayed on the farms.
But the Jews (like everyone else) were beholden not just to economic rationalism, but also to the dictates of their religion. And the Jewish religion, unique among religions of the early Middle Ages, imposed an obligation to be literate. To be a good Jew you had to read the Torah four times a week at services: twice on the Sabbath, and once every Monday and Thursday morning. And to be a good Jewish parent you had to educate your children so that they could do the same.
The literacy obligation had two effects. First, it meant that Jews were uniquely qualified to enter higher-paying urban occupations. Of course, anyone else who wanted to could have gone to school and become a moneylender, but school was so expensive that it made no sense. Jews, who had to go to school for religious reasons, naturally sought to earn at least some return on their investment. Only many centuries later did education start to make sense economically, and by then the Jews had become well established in banking, trade, and so forth.