I was about to answer this question:
when I refreshed the page and saw it was put on hold as off-topic. Now, it might be a duplicate (although I can't find one) but I don't think it is directly off-topic and is asking a reasonable question: why do the E-L equations not work if you substitute in on-shell values for the velocity?
(OP has clearly recently discovered Lagrangian mechanics and is a bit confused about the whole thing, so they don't make this point clearly but it is the heart of their question. Perhaps this counts as insufficient prior research, although that seems a quite high bar to me.)