So why do socialists oppose the petty bourgeoisie?
Principled socialists should oppose the petty bourgeois just as much as the big capitalists (haute bourgeois), because both are part of the larger owning class that maintains capitalism. Small business owners are no less exploitative than big business, and because they are naturally outcompeted by larger, more efficient enterprises, they are often driven to squeeze their workers even more ruthlessly. As this article
https://jacobin.com/2018/01/small-businesses-workers-wages shows, small enterprises offer worse working conditions. As a class the petty bourgeois are the enemies of socialism, because socialism would necessarily require them to surrender their power and capital.
To quote Pannekoek, a founder of Council Communism:
'So long as the great mass of the people were independent producers Socialism could exist only as the utopia of individual theorizers or little groups of enthusiasts; it could not be the practical program of a great class. Independent producers do not need Socialism; they do not even want to hear of it. They own their means of production and these are to them the guarantee of a livelihood. Even the sad position into which they are forced by competition with the great capitalists can hardly render them favourable to Socialism. It makes them only the more eager to become great capitalists themselves. They may wish, occasionally, to limit the freedom of competition - perhaps under the name of Socialism; but they do not want to give up their own independence or freedom of competition. So long, therefore, as there exists a strong middle class it acts as a protecting wall for the capitalists against the attacks of the workers. If the workers demand the socialization of the means of production, they find in this middle class just as bitter an opponent as in the capitalists themselves.'