Your question references X2: X-Men United (2003)—the second film, not the third (The Last Stand). In X2, both characters survive:
In X-Men: The Last Stand (2006, the third film): Cyclops is killed off-screen by a resurrected Jean Grey/Dark Phoenix early on; Xavier is disintegrated by Dark Phoenix mid-film (later revealed to have transferred consciousness to a comatose twin in the post-credits scene, setting up First Class timeline).
So in X2, they're alive because the story hasn't killed them yet.