This is typically the toilet's fill valve. When the diaphragm gasket inside the top cap of the fill valve goes bad, it loses elasticity and becomes hard. When it tries to shut off, it bounces in micro vibrations sending a shock wave back into the piping. You can test the fill valve theory by removing the tank lid and lifting gently on the fill valve float arm. If the noise stops, you've found your problem and should proceed with replacing the fill valve.