This has been an issue since at least Unity 2019 LTS and am still experiencing it in 2022.3x where it seems even worse:
Using an Animation component (not Animator) and legacy animations authored using the Animation window, everything works in editor. However, when I make a build, a handful of objects will randomly not play their animations. Sometimes it even seems to depend on the build. For example, I have a very simple door object with a single, very simple animation. When I build it for Windows, sometimes it works, and when it works, it always works for that build. But then if I rebuild it for Windows again, sometimes it won’t work, and then it will never work in that build.
Other times, objects’ animations work most of the time in a given build, but then randomly won’t some times. The worst case is how I use them to bring menus in and out, and when those randomly fail, the player gets stuck in the game because the next menu panel doesn’t animate in.
For example, I have one UI element that was animating in just fine. Then I made another build and it stopped animating in completely. I rebuilt it 3 more times, still nothing. I added lots of logging and it does appear that, based on looking at various values on the animation component while the animation ought to be playing, that the animation component does indeed think it is playing. But it isn’t.