In most cases, this is caused by a problem with the fill valve inside the toilet tank. The noise can occur when the diaphragm gasket inside the fill valve’s top cap becomes hard or loses elasticity. As the water shuts off, it bounces and sends shock waves back through the pipes. To see if this is the problem, remove the lid of the toilet tank and gradually lift on the fill valve float arm. If the vibrations stop, you have found the problem and should replace the fill valve.
If the vibrations are loud and persistent, you should contact a plumbing professional. Over time, these vibrations can damage your pipes. A plumber can determine if you may need a surge arrester or air chamber to stop the vibrations.