KZ equation, G-opers, quantum Drinfeld–Sokolov reduction, and quantum Cayley–Hamilton identity