There’s way more variables at play here than you can understand. Battery charge, engine temperature, climate control temperatures, where you’re stopped at, if your blinker is on and you’re at an intersection turning etc etc etc.
If you don’t have any malfunctions and it is shutting off at least some of the time, then it is working as designed.