I've had this happen on a couple. If it happens more than once I unscrew it, clean it good, put a drop of blue Loctite on the threads, and this has always worked.
There are some odd balls. I have a 629 Hunter which is a PC revolver that I bought new in 2020. It has a fluted 8.375" barrel, a non fluted cylinder, a square butt, all kinks of Pic rails, and here is the weird part, its a 4 screw!
I can't understand why S&W uses steel Pic rails on a lightweight scandium framed revolver like the TRR8. For that reason alone I won't use the pic rails. I have also used Blue Loctite on fasteners that come lose. However I've never had a barrel nut come lose on any of my revolvers.
I would like to add that I'm not trying to bash S&W. I have and buy a lot of S&W revolvers, both new and used. This is the first new S&W I can remember that I thought was not up to their standards.
The problem with the new 3" 629 I received is, out of the box it looked like it had been knocked around. More than a few scratches, dings, and dull spots. I thought the gun looked liked the finish was a rush job, so I said the hell with it and refinished it. I did not consider sending it back...