For any piece of music to be used in sync with a video (that is, as background music), the musician / copyright owner of the track must first grant a licence to the creator of the video.
The licence for using tracks in videos, films etc. is called a Synchronisation licence (Sync license).
As a result, any videomaker who wants to use any musical work in their video must first have the written Synchronisation licence from the creator.
As the online video market grew huge with platforms like YouTube and Vimeo, the content providers (YouTube) introduced what is called ContentID.
ContentID lets musicians register their tracks directly on YouTube (ContentID registration), and since the registered tracks are then in YouTube's database, the platform can scan all existing videos and find which of them use that track.
For example, if you and your band have released a single and register it with ContentID, you can see which videos across YouTube contain that track.
When YouTube finds that a musical work is used in a video, it sends a message to the owner of the YouTube channel announcing that they cannot earn revenue from that video (the so-called copyright claim).
Whenever there is a copyright claim on a video, the revenue from the ads shown on the video is paid to the musician whose work is used and not to the video maker.
If the videomaker wants to gain the right to collect the ad revenue, they have to buy the Synchronisation licence from the owner of the musical work. With this, they can go to YouTube and ask for the copyright claim to be removed from the video (this process is called a "dispute").
Under YouTube's terms, for a channel owner to earn revenue from ads shown on their video (so-called monetization), they must first have bought all the corresponding rights (when music is used, they must have bought the Sync licence). Otherwise all the revenue from the resulting copyright claim is paid to the music creators.
If there is a copyright claim, it is shown publicly under the video description. To activate the whole process above, the tracks must be registered with YouTube ContentID - a process handled by companies that partner with YouTube.