Initially, in the era of feudalism, the inhabitants of cities were called bourgeois (German: Burg - a fortress city), opposing them to a much larger rural population. Until the 11th century, there was no particular difference between a city dweller and a peasant, both of them were under the rule of the lord. However, starting from the XI century, the liberation of urban communities began and many cities received independence, not noble seniors, but the richest and most respected townspeople - merchants and guild leaders - were already participating in their leadership.
The bourgeoisie of medieval states included rich craftsmen and poor apprentices and shop workers; and usurers, and often financially dependent merchants. These people were a layer between the elite of society - the nobility and the working class. The privileged position of the townspeople in the 18th century caused frequent complaints from peasants about the pride of the inhabitants of cities, and gave rise to distrust of the rural population.
Over time, the most successful bourgeoisie came to power thanks to money. Nobility of origin in the 19th century replaced by the possession of property ... this is how the first capitalists appeared. And the dislike of the working class eventually spread to the wealthy who exploited the working class. As a result, the revolutionaries of all who had money began to be called bourgeois!
Interestingly, in post-Soviet countries the word "bourgeois" is colloquially used to denote something foreign, often Western European or American, and "bourgeois" is sometimes used in the sense of a resident of the USA, Europe or another capitalist country (outside the borders of the USSR).