The European Council agreed in 2017 (see page 4) that a united Ireland would be part of the EU:
The European Council acknowledges that the Good Friday Agreement
expressly provides for an agreed mechanism whereby a united Ireland
may be brought about through peaceful and democratic means; and, in
this regard, the European Council acknowledges that, in accordance
with international law, the entire territory of such a united
Ireland would thus be part of the European Union.
The key word is "such", referring back to the "agreed mechanism ... through peaceful and democratic means". Only if Ireland were united using this mechanism would the EU automatically accept the whole territory as a member. The mechanism in question is described in the Belfast (or "Good Friday") Agreement (page 4): the Secretary of State for Northern Ireland can direct that a referendum be held in Northern Ireland; if such a referendum indicates a majority in favour of unification, both the UK and Irish governments are bound by the agreement to give effect to unification.
This restriction also means that the EU does not see this declaration as setting a general precedent for members annexing other territories. This was apparently of concern to the French:
French lawyers were concerned. Could this declaration create a
dangerous precedent, since European Council declarations carry strong
legal weight?
... The excruciating care with which the text had been
drafted was cited to convince the French Ambassador and his lawyers.
... The word ‘such’ related back to the
‘agreed mechanism’ in the Good Friday Agreement. Thus, the wording
could not be applied to any other situation.
[French Ambassador] Sellal and the lawyers took the explanation to
President François Hollande. The French dropped their objections
immediately.
(For this quote and other details of the discussions leading up to this statement by the European Council, see chapter 14 of Tony Connelly
Brexit and Ireland: The Dangers, the Opportunities, and the Inside Story of the Irish Response.
Penguin, 2017. ISBN: 978-1-84488-428-5)