iphone rings through speaker with earphones connected

This is normal, provided your ringer switch is set to ring.

Setting the ringer switch to silent will prevent the ringer from sounding from your phone's internal speakers, but not through external Bluetooth or wired speakers/headphones.