Near-infrared spectroscopy of (proto)-planetary nebulae: molecular hydrogen excitation as an evolutionary tracer