Why? Perhaps a chattering automatic valve of some kind. You can test for this by shutting off suspected appliances one by one to see if the hammering stops.
Another big cause is unsecured pipes. That's a tough one, because you'd need to isolated the area and then open walls to fix it. Leaky toilets are very
likely the cause of hammer occuring when "nothing" is running.