Katie Granger on MoviePilot attempts to explain it:
Whilst filming Apocalypse Michael Fassbender told ScreenRant that the reason Magneto follows the resurrected god-mutant Apocalypse/En Sabah Nur is because, when the big blue shows up, he's at the lowest point in his life.
If you've seen the movie you'll know why — after still trying to work through the trauma of losing his family in the holocaust of WWII (as seen in X-Men and X-Men: First Class), tragedy strikes for him once again in Poland.
In a nod to his comic-book backstory, Erik's wife and young daughter are accidentally killed during a confrontation by a mob once Erik's identity as Magneto is uncovered.
At his lowest point, when Apocalypse shows up, Magneto accepts the outstretched hand as a way of unleashing his anger and pain back upon those he holds responsible, as Fassbender elaborates:
"[Apocalypse has] caught [Magento] at a very low, vulnerable point where he doesn’t really care anymore whether he dies or not or what happens, so he’s like, 'Yeah I’ll join this guy. I’ll go on this path of judgment.'"
When Magneto decides to Judas it up, it's presumed that Mystique's appeal to the sense of his family he still retains for her and Charles Xavier (James McAvoy) is what motivated him to turn against Apocalypse.
However, she does find this unbelievable and argues that another reveal might have worked better.