Thanks to the new EU / Japan trade deal, it doesn't even need to be in the EU.
I don't think Honda's decision was totally do with Brexit. They produce Civic's all over the world (Canada, the US, Malaysia, Brasil) and relatively few in Japan. But the Civic is due a refresh, the current model is 2016 and historical Honda don't really let the Civic go more than 5 years without a refresh, and concidently or not 2021 seems to be when production is going to taper off.
If you can remove uncertainty from your business then it's a no brainer. The capital costs are largely off the books for a factory as old as Swindon, so you're only really paying to exit.
You don't have to pay to ship the cars across the world if they've produced in the market you're selling to. If you're doing high volumes it doesn't make sense to stick that many cars on boats.
However, Honda doesn't sell well in Europe, with fairly small sales figures it's not too surprising they're closing the factory down.
Honda's UK plant output less than 50% sold in the UK/EU (35%ish EU27, 15% UK) so the EU/JPN deal really doesn't have massive amounts to do with it. It's certainly a factor though and it helps increase the competitiveness of the Japanese plants facing the EU, and obviously Brexit decreases the UK plants competitiveness (as 40% of it's components come from the EU)
Honda's other European facilities: a logistics hub in Belgium and a small factory in Turkey (produces 50k vehicles per year to Swindon's 150k) are supposedly affected as well. I imagine the Turkish plant is simply too small to run by itself.
I've no doubt btw that Honda's Press release tomorrow will steer clear of Brexit, talking about global strategies, electric vehicles, tough markets and maybe a reference to instability, I mean why would you want to piss off 50% of your potential UK consumers.