Chosen Solution
In the past week my phone has died randomly around 4 times. Whether it be on 50%, 30% or 40%. This never happened until I got my battery changed about a few months ago. But it was fine until about 3 weeks ago. It had become more frequent.
That may depend on the battery quality..or was the old one replaced with an original one ? In any case within iOs 12 in Settings/battery you can check the health state of the battery and other useful info. A worn out battery may not supply the peak power necessary for the phone to perform certain tasks and the iPhone gets throttled or shuts down.
Sounds like battery needs to be replaced and also check the good connection between battery and battery connector.