Hi,
It seems you are not the only one with this issue, Samsung Community has a lot of people who are experiencing this same issue.
https://eu.community.samsung.com/t5/galaxy-z-fold-z-flip/my-galaxy-z-flip-4-keeps-shutting-down-when-folded-and-often/m-p/9202187#M20134
You didn’t mention if the problem was there before or after the battery replacement so it’s not clear if it will be the same problem exactly or whether there is a need (after the battery replacement) to enter reset mode and clear the cache first to see if that changes the situation.
Alternatively you can power off but select safe mode to see if it runs without the issue, if it does then you’ll need to identify the app that is causing the problem & remove it.
Another option would be to make sure you running the latest software update.
If either of those don’t resolve the problem then your last ditch effort would be to do a factory reset and if that doesn’t cure it then you may have the flex issue that is mentioned in the link.
Hope this helps