I was thinking about this while playing FIFA yesterday. England, Scotland, Wales, and Northern Ireland are all independent "nations" for soccer tournaments. Hell, even Gibraltar competes independently, and it has approximately 1/3 the population of the American suburb where I live.
Yet for most sports at the Olympics (and other major international competitions), athletes from the UK compete as a part of Team Great Britain (sorry, Northern Ireland). What in history led to the UK consolidating some national sports and keeping others separate?
Like many issues related to international cooperation the answer is both surprisingly straightforward and extremely complex. In a nutshell, an Olympic Committee at international level was formed before any Olympic committees had been formed at national level, whilst an association of football associations at international level was formed after associations had been formed at national level. Except, of course, that it wasn’t that simple: a British Olympic Committee of sorts had been formed in 1865, called the National Olympian Association (NOA) but which ceased operations in 1883. This was probably what inspired Pierre de Coubertin to revive the ancient Olympics in a modern form; and going back even further, the NOA itself was formed from the Wenlock Olympian Society (formed in 1850), who have held the Wenlock Olympian Games since then (and I believe still do!).
The international Olympic committee, the IOC, was formed in 1894 (with the first modern Olympics being held in 1898). Their plan for the Olympics was quite far removed from the ultra-polished spectacle we have today; all athletes were expected to be amateurs (with the notable exception of fencers) and had to find their own accommodation. The athletes came from whoever either happened to be in Athens in 1898 or could afford to get there - the Wikipedia article says that many of the British athletes were from the British Embassy, and I remember reading that another countries entire team was made up of sailors from a ship that happened to be in port that week.
Those first games were held in Athens and despite some pretty major teething problems (mostly related to funding), were a phenomenal success. One issue was notable though: the rules for several sports were not codified at international level, so many countries played using slightly different rules to others. With the advent of an exciting era of international sport beckoning, officials in many sports were suddenly falling over each other to get their sports properly codified - in the next two decades virtually all of the major European sports formed committees, associations or federations at national and international level. Organisations were formed at international level in tennis and fencing in 1913, water sports in 1908, athletics in 1912, shooting in 1907 and many more.
In the case of the United Kingdom, the organisations for various sports organised on a British level (as opposed to English/Scottish/Welsh/Irish) simply because they didn’t have the popularity or resources to organise more regionally. If we move away from Olympic sport briefly and look at the England cricket team: it isn’t actually the England cricket team (as it is always referred to as), but the England and Wales cricket team. Wales simply didn’t have enough people interested in the sport or the resources to form their own board, and merged with England to form the England & Wales Cricket Board instead. But I digress.
Now onto football, and why the home nations (England, Scotland, Wales & Northern Ireland) compete individually. The first football association to be formed was The Football Association, which regulated English football and was formed in 1863 - predating the modern Olympics by 35 years. You’ll notice that the word ‘England’ isn’t in their name - that’s simply because it wasn’t necessary as they were the only one! The Scottish Football Association formed in 1873, and the Football Association of Wales in 1876.
The international level of associations is FIFA (Fédération Internationale de Football Association, literally ‘International Federation of Football Associations’) and was formed in 1904. Originally it was comprised of the national associations of Belgium, Denmark, France, the Netherlands, Spain, Sweden and Switzerland - the FA would not join until 1905, and with the other British associations left in 1919 at protest against FIFA refusing to exclude the associations of the Central Powers of WW1. They rejoined in 1924, but the FA would again resign in protest against rules relating to payment for athletes in 1928, not rejoining until 1946. Perhaps ironically the organisation they were protesting with was the British Olympic Committee.
There’s one other organisation which needs to be mentioned here: the International Football Association Board (IFAB) founded in 1886. Their role is to regulate the rules of the sport, and there are five members:
FIFA have stated that the rules of football are decided upon by IFAB.
So, in a nutshell: the ‘home nations’ compete separately because they formed national-level associations before the international-level one, and because they all sit on the board that regulates the rules.
Other territories can form their own football associations and apply to join FIFA. As a simplification, if a territory is not under the jurisdiction of an existing football association then they can form their own (as is the case with Gibraltar, the Faroe Islands, Hong Kong, Macau etc). Some territories have their own quasi-independent associations but are not eligible to apply to FIFA (Catalonia, the Basque Region etc), whilst others could apply but haven’t for whatever reason (Greenland).
Conversely, the IOC will only now take applicants from independent countries which are recognised by a majority of UN states - so Monaco could go to the Olympics, but as they aren’t in FIFA can’t go to the World Cup.
I hope this at least goes part way to answering your question!