There is an element of luck involved (i.e. for extremely viral videos), but most of it is iteration - learning how to record and mix audio properly, learning how to make the best of the lighting you have available, learning that if you want to make live coding videos you need to increase your text size to an uncomfortably large size so that viewers have a more pleasant viewing experience, etc.
[1]: https://www.youtube.com/watch?v=Ece_NCcgiMY - one of my earliest videos
[2]: https://www.youtube.com/watch?v=b1yECfF7Qyg - my latest video
Then another.
Then another.
Etc.
The algorithm will try to find an audience for them if they are sonewhat something some people might want.
But without actually making videos there’s no point in thinking about the algorithm. It is entirely empirical.