Mechanism and control parameters of the coupled structural and metal-insulator transition in nickelates