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. 😆
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.