They had to dust off some law from the 1800s, I think. Basically Merkel has managed the immigrant crisis poorly, by underestimating how many Germans are racist and paranoid when you scratch the surface, and not engaging meaningfully with how that demographic can be talked round, nor how refugees can be integrated into German society. Don’t get me wrong, the situation is an incredibly difficult one to manage, but in this case she’s to some extent the victim of her own half-measures. So in order to attempt to placate the reactionary right (and increasingly right, too) she’s attempting another half measure, in the negotiated return to Turkey of a portion of migrants from Europe as a whole. For this she is dependent upon the goodwill of Erdogan - and Erdogan is a dickhead.
Frankly I don’t think that sending a trickle of refugees or migrants back to Turkey will be enough to calm the situation in Germany now, anyway - Merkel made the mistake of letting them get their pitchforks out and now the mob is banging on the castle door. There are also a variety of other historical errors made which are contributing to inflaming tensions (such as ignoring the extreme right generally - for example, doing nothing as they cornered the private security market in several states, then contracting these neonazis to guard refugee centres). But now Merkel finds that, having done as little as possible for much of her CHancellorship, she’s now in a catch-22; she finds that the valve by which she hoped to release the pressure of xenophobia in Germany, is controlled by Erdogan, whose demands (and much of his policies, generally) likely to increase xenophobic pressure in Germany.