Lewis Hamilton suffered a shock exit from Q2 in a dramatic qualifying session that also saw his teammate Charles Leclerc crash out.