This question already has an answer here:
- Why the Principle of Least Action? 10 answers
I remember asking my second year Mechanics teacher about why do the Lagrangians give the equations of motion. His answer was that there is no answer to that, it is an empirical fact, and that asking the why of the Lagrangians is the same as asking why Newton's laws hold.
I understood his point but I wonder if you have a better answer. Why do Hamiltonians and Lagrangians work?