The CJEU found that the Directive 2008/115/EC of the European Parliament and of the Council of 16 December 2008 on common standards and procedures in Members States for returning illegally staying third-country nationals must be interpreted as precluding a Member State’s legislation which provides for a sentence of imprisonment to be imposed on an illegally staying third-country national on the sole ground that they remain, without valid grounds, on the territory of that State, contrary to an order to leave that territory within a given period.
Source: official link