It seems like a lot of historically prosperous countries have also had strong navies. Is there any connection to the two?
Some examples would be:
USA in 2018: Worlds strongest Economy and Worlds Strongest Navy.
18th Century Britain: World superpower, Strong Economy, Most feared Navy of the time, 17th-19th century
Chola Dynasty: Great economy, Considered strongest Navy from 300BC to 1300AD.
Lots of rich inland states too, but you're right that there's a trend of wealthy thalassocracies; to that list you can add the Dutch Republic in the 1500s-1600s, the Genoese and Venetian Republics in the Middle Ages, and Athens and Phoenicia in the classical world. To some extent, there are the Portuguese and Spanish Empires too, though Spain was more of a land power with some naval adjuncts.
The simplest answer to this is that navies have historically been a uniquely expensive form of power, more reliant on capital than on manpower (unlike armies). Ships are expensive to build and very expensive to upkeep. Coastal states that rely on trade rather than agriculture often become fairly wealthy, and not only that, tend to have that wealth distributed more widely--oligarchies rather than autocracies. Additionally, the reliance on seaborne trade means that they tend to have access to a pool of skilled seamen, which is a historically very important factor; you can conscript landmen en masse to the sea (like Bourbon France did) but that's unlikely to work very well. (The Royal Navy estimated that it took three months to train a landsman to be a net help to the ship rather than a liability.) Finally, because the wealth is distributed fairly widely in mercantile states, then if the state can maintain a public consensus, it can mobilize more of that wealth--a good thing, because it will need it to upkeep a navy (i.e., the merchants are more likely to vote for taxes and contribute their expertise if they can see that a strong navy means protection for their trade).
This is in contrast with the fleet of, say, Tsar Peter the Great of Russia; because Russia was a landowning autocracy rather than a mercantile oligarchy, its power and wealth came from landowning nobles who tended not to care about seapower. Peter himself was a navy fanboy, famously touring Dutch and English shipyards while incognito, and built a fairly impressive fleet that helped to win the Great Northern War, but once Peter was dead the fleet was neglected due to lack of interest. This is a pattern that's tended to repeat among large land powers, the opposite of the small wealthy thalassocracies: they might occasionally surge forth upon the sea, sometimes with very impressive results (see: Zheng He and the treasure fleets), but lack of institutional interest means that they often have a hard time sustaining those fleets over time.