Is there special legislation in EU law to permit free ports, or are they implicitly permitted on the basis that goods become subject to tariffs as soon as they exit the port into the member state?
It's quite complicated and it was the subject of a claim on fullfact.org. The claim reads:
The EU is the only place where free ports don’t really exist.
And the conclusion was:
Free ports do exist within the EU, although in a more limited form than elsewhere in the world.
The detailed explanation, quoted verbatim from fullfact.org as it's rather complicated and they put in the effort to carefully research it:
However, some experts have claimed that EU law limits the scope of free ports.
Professor of EU law Catherine Barnard wrote last year that while there are many potential benefits of free ports, within the EU “it is not, however, easy for companies to benefit from these arrangements.”
“Approvals for FZ [free zones] are also subject to EU state aid rules.”
EU state aid rules generally prohibit EU governments from providing support to certain companies over their competitors. This can limit the abilities of member states setting up free ports with tax incentives (as this would essentially provide support for businesses within free ports compared to those outside of them).
Professor Barnard illustrated this, saying: “The difficulty of obtaining an FZ status can be illustrated by the Shannon FZ in the Republic of Ireland. The Shannon FZ was successfully launched in 1958 but, upon Ireland’s accession to the EU in 1973, the incentives in the Shannon FZ were limited in order to comply with EU state aid rules (e.g. the 0% corporate income tax was increased to 10%).”
EU rules also mean it’s more difficult for businesses to engage in something called “tariff inversion”. Because tariffs on component parts are often higher than tariffs on finished goods, it can be advantageous for a business to transport components to a free port, turn them into finished goods, and then import those finished goods into the rest of that country with a lower tariff.
A 2005 paper from a UN body said: “The [European] Commission does allow the establishment of free zones within its territory but its definition of free zone is a very narrow one.”
Quoting from the third link in the quote above, by UK in a Changing Europe, the following programmes exist in the EU for free ports (these are selective non-consecutive quotes, just to illustrate the different programmes mentioned in the article):
The main programme under EU law for the creation of FZ is the Processing under Customs Control (PCC) which applies to the processed products when they are released into free circulation, rather than the imported goods.
Another EU programme is Inward Processing Relief (IPR). This releases customs duties and import VAT on goods that are imported from outside the EU to be processed and re-exported to markets outside the EU. Duties are thus paid only on the finished product. An example of an IPR is the operation of the Old Free Port of Hamburg.
Outward Processing (OP) is a programme which allows goods to be temporarily exported abroad for processing purposes without subjecting them to (all or some) import duties upon their import back into the EU.
Specific to your question, it seems this is covered by a part EU law called the Union Customs Code (regulation text here). More specifically, chapter 3 section 3 titled Free Zones. Its first article, article 243 reads:
Designation of free zones
Member States may designate parts of the customs territory of the Union as free zones.
For each free zone the Member State shall determine the area covered and define the entry and exit points.
Member States shall communicate to the Commission information on their free zones which are in operation.
Free zones shall be enclosed.
The perimeter and the entry and exit points of the area of free zones shall be subject to customs supervision.
Persons, goods and means of transport entering or leaving free zones may be subject to customs controls.