My wife and I took a cruise for our honeymoon that stopped in Kotor, Montenegro. For fun, we rented a car and drove up to Split in Croatia along the sea. That means we got to drive through that strip of Bosnia. We stopped and had lunch at a little pizza place in Neum, Bosnia.
The people in the pizza place asked us how in the world we came to be there. 😆
Yeah, they actually built a goddamn huge Pelješac bridge last year to circumvent this part, so if you're travelling along the croatian coast down to Dubrovnik you don't need to cross the Neum border any longer. They actually spent like half a billion euros on that project just out of spite. That's the balkan thing.
TL;DR they gave the coast to the Ottoman Empire hundreds of years ago for free because they were tired of fighting invaders from the sea. Free protection in exchange for cities they weren't able to defend anyway.
Most of the towns along the sea were parts of the Venetian Republic and share a lot of common culture through that. There's no dividing them at this point.