How did European tiny states, like San Marino, Monaco, Andorra and Liechtenstein (excluding the Vatican, whose survival is clearly connected to religious reasons) manage to not be absorbed by bigger national states, in the heyday of their respective expansions?
The individual reasons for the survival of the European microstates can be read from their histories on their respective wikipedia pages but in general it comes down to two main factors; firstly by the 19th Century they were already protectorates of larger neighbours and, secondly, they were too small to bother with.
As an example of the first point, both Andorra and Monaco were effectively French protectorates and had been for centuries. Liechtenstein was initially part of the HRE, briefly under French control as part of the Confederation of the Rhine and then a protectorate of the Austrian Empire.
In almost all cases, these were states with little or no military power and so posed no direct threat to their neighbours. They had few natural resources and they had correspondingly small populations, neither of which were worth invading to exploit.
The exceptional microstate was Malta. After its capture from the French, it lost its independence and became part of the British Empire, remaining so until 1964. The difference being that Malta had great strategic value as a base in the middle of the Mediterranean Sea.
There is a usefulness in having a micro-state closely allied to your larger country, though still technically independent (like a small protectorate).
These still exist to a certain extent today. The UK gets to use Jersey and the British Virgin Islands as tax havens. The Chinese have Macao and Hong-Kong special administrative regions as economically outside the main Chinese control, to their benefit. Macao (again) and Monaco exist as gambling and banking venues for the protector state for behaviours which are illegal in the country proper.
The older micro-states in Europe are still fully independent, though the more modern ones (Macao, Gibraltar, even Guantanamo Bay sort of) have a fuzzier definition, but serve the same purposes.
Since having these satellite micro-states is useful, they survive.
Monaco is a playground for Europe's ruling class; an occupation would be anathema to this group. Likewise, the Vatican for religious reasons.
San Marino, Andorra and Liechtenstein are all city-sized states in mountainous areas; densely populated, easy to defend, and not particularly valuable otherwise (the main assets can disappear on their feet), therefore not worth conquering.