The EU gets to do this the same way that the US can use secondary sanctions to enforce its will on Iran despite the EU notionally still being in the JCPOA. There've been noises about protecting European companies doing business in Iran from US sanctions - note that they have been coming from people on the margins, this isn't going to happen. That kind of power is just the privilege of being a large, wealthy trading block and it's basically the reason the EU exists.
What would happen if The Netherlands or Poland tried to individually enforce a regulation as onerous as the GDPR on all companies holding data on their citizens? Nothing. Either companies would just withdraw from those markets or they would rely on the impossibility of enforcement. The EU is a sovereignty compromise that gives up some local de jure sovereignty for greater EU-wide de facto sovereignty.
If the US tried to override the second part unilaterally, Europe would probably ban exempted companies from dealing with European customers unless they opted into GDPR or would otherwise fall out of scope without the exemption. They'd therefore have trouble dealing with European banks, shipping companies with a presence in Europe, etc.
Not to mention, what if Europe tried to exempt their companies from dealing with the annoying US laws? It would become a messy war of exemptions and consequences.
This game of "we're too special to have to follow your laws even if we want your customers en masse" is a dangerous game to play.