Sea of Thieves is a big game, with loads of freedom, and that means that sometimes, yes, you're going to sail yourself into something and get stuck. Whether you're beached on a sandbank, or have managed to get wedged on a rock, don't panic. It is possible to get yourself free again, with a few tricks and a little patience.
If you're grounded, and the ship isn't working itself free, the best option is to raise your sails, raise the anchor and turn the helm hard in either direction. This should cause your ship to bob around, and eventually work itself loose. The downside is that you will take damage while doing this, so have crewmates standing by to bail out any water and patch up any holes.
If it looks like you're really stuck, you may want to take any precious cargo off the ship first, hide it on whatever island you're trapped on, and have someone guard it until your ship is loose. If the ship is truly, irreversibly trapped then the game may eventually despawn it for you, and spawn a new one, but you don't want to risk losing any treasure if this happens.
As a last resort, you can always scuttle the ship - which means sinking it on purpose. You can do this from the My Crew menu, but it requires a vote from your crew. Don't take this option lightly. The game will give you a new ship, and teleport you to its location, but any cargo and other items on your old ship will be lost forever. That'll teach you to watch where you're going.