I was hoping someone would have an explanation but since there are none, I looked it up myself.
https://www.theguardian.com/science/2024/jan/30/why-are-moths-attracted-to-lights-science-answer
Tldr: They try to tilt/level their wings with light source thinking it's sun. Hence they end up getting confused as the light isn't coming from the sky and their flight path gets messed up trying to align with it.