Here’s a definitive explanation of how YouTube’s search and discovery (related videos) works. In my experience, this system is fundamentally flawed and often suggests completely random videos seemingly unrelated to the current video I may be watching. But I guess there’s some sort of work being done to always make it better.