I had the same problem, it was caused by a call recording app called call recorder pro,
there was a setting in the app called AUTO SPEAKER which i had enabled, once i disabled it the phone didn't default to speakerphone.
This was so far the best reply. Had the same problem of auto speaker. This was due to the call recorder app i had installed. Nothing else is needed, just find that stupid app you might have installed and change the setting.

Thanks