Lewis Hamilton claimed his first pole position for Ferrari by edging out Mercedes' George Russell in qualifying for the Mexico City Grand Prix.