We had banging pipes that went off randomly throughout the day in our apartment even if nobody was using the water. It would only be quiet if you let out some water.
This water hammer was eventually was fixed with this Sioux Chief Water Hammer arrestor. IT really works! However 1 year later, the problem has come back occasionally, but quickly resolves itself in a few seconds.
EDIT: Also months later, the faucet began to leak and drip, wouldn't stop even if you shut off the valves under and it turns out the faucets also needed to be replaced too and fixed the leak issue. So look into that as well