Chosen Solution
Why is the sound of my phone not working unless I insert earpiece?
Does your phone have audio in any function without the connected earpiece? For example, does your phone ring? Can you watch a video on YouTube or something similar? Is audio in phone calls normal? Isolating this can help determine the issue. I would have a look at the iPhone No Sound page for a pretty thorough list of causes and fixes.