Gravitational collapse to extremal black holes and the third law of black hole thermodynamics