Chosen Solution

When I put earbuds in my phone my S4 Mini will turn itself off and attempt to restart itself which it will fail until I unplug my earbuds and remove the battery and put the battery back in and then start it back up without the earbuds plugged in…why is it doing this?

It sounds a software problem but maybe a physical issue caused it (Dust or Broken pin). Try at least to clean its hole with a gentle brush when the entrance is downward. If you have technical hands and experince with phone repairs try simple to replace this little piece. Regards