To eventually become a mathematics lecturer in the UK, does undergraduate degree have to be from a good university? What is the initial process to become a Mathematics's lecturer at a University in London. I want to be able to lecture in a top university in the United Kingdom such as Kings College.

What is the academic ladder that I will have to climb?

Would my undergraduate program have to be from a good university or could I graduate from a mediocre university and then enroll in a masters program at a well known university followed by a PhD?

My goal is to become a lecturer and go into research in Mathematics.
First, let me point out that a career as you describe it not entirely plannable: There are many more who want it than who get it, and even if you are talented and work hard, success is not guaranteed.

It probably won't matter where you did your undergrad once you've received your PhD, although going to different universities could be beneficial, as it would expose you to more different academic cultures etc.

Once you have received your PhD, you'll want to do a good postdoc. Going to some top university abroad, or becoming a Junior Research Fellow in Cambridge or Oxford could be good choices. Make sure that you develop contacts at your desired university.

After some postdoc experience you can apply for eg a Royal Society Research Fellowship or an EPSRC Early Career Fellowship, to be held at your desired university. During that time, try to convince the university to offer you a permament position after the fellowship ends.