Your iPhone has a loose connector plug that attaches the ringer mute switch to the logic board. To repair it requires that you disassemble the iPhone down to the plug. This will mean that you have to open the iPhone and take out most of the components.

Hardest part is to remove the battery due to the adhesive backing. To avoid damaging the case, use a suction cup to pull off the display touch screen glass (after removing the two screws holding the case together. Just follow the tear apart instructions for the iPhone.

Reseating the connector will usually fix this problem.