3D modelling of the impact of stellar activity on tidally locked terrestrial exoplanets: atmospheric composition and habitability