Lewis Hamilton has surprised the crowd and himself by securing his first sprint pole position for Ferrari in the final moments of qualifying at the Chinese Formula 1 Grand Prix.