Often, but not always, it’s a part of shallow sea more or less trapped behind coral reef. The reef is built by the coral themselves rather than being somehow deposited. Other lagoons can form due to deposit of, for example, sand. And anything that gets deposited has a habit of being eroded from somewhere else. Update <> Then posting a different question wasn’t a good move. OK, we’re not dealing with a coral lagoon. Let’s talk about a lagoon more or less cut off from the sea, but not entirely, behind a series of sandbanks. Once upon a time those sandbanks weren’t there. The sand was eroded from elsewhere and, probably due to tidal action, it was dumped in a shallow area by the shore. That built an obstruction and the tide dumped more sand there until, eventually, there was a sandbank. That continued growing until part of the sea, the bit behind it, formed a lagoon.