The thing which makes these sounds is a type of 鹿威し (Shishi-Odoshi) or scaredeer, it acts similar to as what a scarecrow does, and the sound it makes scares away the wild animals.
And as for what device specifically makes that sound in Japanese gardens and onsen, is 添水 (sozu).
Sōzu is a type of water fountain used in Japanese gardens. It consists of a segmented tube, usually of bamboo, pivoted to one side of its balance point. At rest, its heavier end is down and resting against a rock. A trickle of water into the upper end of the tube accumulates and eventually moves the tube's centre of gravity past the pivot, causing the tube to rotate and dump out the water. The heavier end then falls back against the rock, making a sharp sound, and the cycle repeats. This noise is intended to startle any herbivores such as deer or boars which may be grazing on the plants in the garden.