David Cameron had hoped to rein in migrants' benefits ahead of the EU referendum 