How are tides produced?
The gravitational pull of the Moon (and the Sun) on the Earth’s large water bodies and the centrifugal force of the Earth-Moon system cause two tidal bulges. As the Earth rotates, we experience high and low tides twice a day.
The Moon’s gravitational pull is greater on one side of the Earth than on the other, while the centrifugal force of the rotating Earth-Moon system is greater on the side opposite the Moon. As a result, the Earth’s water mantle is drawn into an elongated ellipsoid. The result is two tidal bulges, one on the side nearest the Moon, the other on the opposite side of the Earth. Due to the Earth’s rotation, those tidal bulges are swept over the surface, producing alternating high and low tides in coastal areas. Lunar tides may be strengthened or weakened by the gravitational pull from the Sun, depending on the lunar phase. Similar tidal effects on the solid Earth do exist, but they’re much smaller, since rock is less malleable than water.
If your sand castle is ruined by the rising sea, blame the Moon. High tides and low tides are caused by the Moon's pull on the Earth's oceans. Sometimes, the Sun makes them even stronger.