Ok, so that's a really big question and apologies for the brevity of the answer here. The answer really lies in the dusty old subjects of politics and history, going back a long way.
London was actually founded by 'immigrant' Romans who invaded and set up a settlement on the banks of the river. There wasn't much here before they arrived. You can see what the Romans built at the Museum of London if you are interested.
And then the city gently expanded for several centuries, reaching around a million inhabitants in
People have come to live in London for various reasons over the years, and most them are as relevant today as ever. The one reason for immigration that seems to have dropped off the relevancy list is political or territorial expansion to take over London. The last people who tried this were the Romans and the Vikings.
Other factors that are still just as relevant today are the need to look for better opportunities (the never ceasing search for safety, food, work, throughout history). This kind of immigration has brought people here from all over the world for centuries. Some for mild economic betterment, some fleeing for their lives.
The combination of Industrialisation and a growing British Empire meant that London people from all over the world were trading in London by the 1800s and the population grew rapidly.
The Port of London was the first place where trading ships disembarked and many different communities have left their mark here. There's still a strong Vietnamese community here, a Norwegian church and a Finnish Church. London's very first Chinatown was in the Port of London before it migrated to the West End in the 1970s.
The narrow streets of the East End has attracted migrants since the sixteenth century. The word 'refugee' was first coined to describe the French Huguenots leaving oppression in France to seek 'refuge' in London.
Following the Huguenots came waves of Jews escaping pogroms in Spain and centuries later Russia. Irish people and Italians escaping the hardships of poverty settled in the East End too and it was a squalid rough tough neighbourhood full of people trying to better themselves.
Some of the poor newcomers did well and by the end of the nineteenth century had escaped the slums of the East End and moved to brand new London suburbs where Victorian builders built swathes of brick terraced houses for the urban working class.
The world wars reduced population in London but from the 1950s there was an upward trajectory again as people from around the Commonwealth lands were invited to come to rebuild post war Britain. Many people from India, Pakistan, Bangladesh and the Caribbean took up the invitation in the 1960s and settled in tight communities across London, far from home.
Instability across much of the world has meant a steady trickle of people continue to choose to migrate to London as London has a reputation of being economically strong city in comparison. Over the last thirty years wars in Bosnia, Serbia, Africa and the Middle East continue to result in people choosing to settle in London. London has earned a reputation as a world financial centre and as such attracted international investors and financiers who have created industry around wealth and financial services.
Membership of the European Union and free trade movement has meant that the flow of people has never been more intense. Over the past twenty years, Polish has risen to become London's second language as Polish migrants, along with other fellow European nationals have settled here.
London has proved time and time again it is a magnificently tolerant city where people of different cultures and religions can rub along together. Immigration is nothing new and we should always remember this.