I am not terribly familiar with the inner workings of the Samsung Z Flip family, but I suspect that a wire, perhaps a battery ribbon, may have worn out over time and cycles of flipping. Moving parts will always wear out, and after enough cycles, components that are subjected to slight tension or bending forces will eventually break.
When you flip it, perhaps this malfunctioning wire is pulled out of position and there is no contact being made, causing it to lose power completely, shutting it off. It could also be the opposite– Some exposed wire could be shorting with another, causing it to restart.
I would take the phone apart and inspect the state of the cabling inside of it, looking for any obviously worn ribbons or wires.
crwdns2934105:0crwdne2934105:0
crwdns2934113:0crwdne2934113:0
crwdns2915270:0crwdne2915270:0
crwdns2889612:0crwdne2889612:0
0