The short answer is that he often doesn't.
Also it's not a producer or beatmaker's responsibility to do this. He makes the beat. It's on the artist and the label to clear the sample. The producer never has to clear any samples unless it's their project. Cool producers keep track of what they sampled to help and artist and their team out, though in case they do want t clear it.
Some of the info in here is legit and some is way off base re: Alchemist and Madlib too.
So on the projects they actually try to get samples cleared, they very often don't. The last few joints Alc bothered to clear through TDE, he had some that where they had to pay 100% of the publishing to the sample holder, and that's what happened with Brreak The Bank, but he and Q took the L on that because they wanted people to hear the song. Other sample holders straight up said "you can't use the beat." That's what happened with Alc on Hoover Street for the same Q album.
And on the Bandana album, Gibbs and Madlib had some songs that didn't get cleared as well as some sample holders that also wanted 100% of the publishing. John Gotti Karate was a song everyone wanted to hear and that didn't get cleared at all. BTW I'm very surprised they even got the Bandana samples cleared officially and cleanly.
A lot of stuff you don't hear about is shyt they don't bother to get cleared. For example, Benny released Plugs I Met for a few hundred copies on CD. That's it. Besides that it's streaming numbers. Assuming whoever Alc sampled even finds out about it, it's not even worth the lawyer fees for them to sue. They could reach out and ask for a little cash under the table, and that does happen from time to time.
Also, Alc and Madlib sample more obscure shyt these days. They aren't looping up Thriller by MJ. Alc is sampled Japanese jazz fusion records and Hungarian prog rock. Madlib has been in foreign underground vinyl crates for a long time.
Alc used to dice and chop up more samples and now does collage more loops on top of each other, but for the most part they're foreign and rare loops, and they're going on projects that are selling small quantities of vinyl with high profit margins, but not a high dollar value at the end of the day worth pursuing for anyone that may realize they've been sampled.
Again, a lot of the shyt that Alc and Madlib sample is only obvious when you go to Whosampled afterwards and hear it. But most Japanese jazz fusion artists from the 70's and 80's are not streaming Yacht Rock 2 in 2019 to see if they got sampled or not. And Alc still throws out some crazy chops that are hard to find, although his current phase definitely is more multi-layers of loops like you said.
And check 1st Infantry. Most of that shyt is chopped up real good, but the label only had to clear like 3 samples for that entire project.