What causes the Earth to have magnetic poles?
Well, firstly it's important to recognise that the poles are merely the extremities of the shape of a magnetic field - the earth's magnetic field.  All magnetic fields have polarities as such.

However, you're asking why the field itself even exists, I gather.  In this case it's generated by electric currents in the conductive molten iron (and other metals) in the core of the earth, as a result of convection currents generated by escaping heat.   This is known as a geodynamo, and is one way of generating a magnetic field.  However, exactly why this occurs is still under investigation.

More is available in this Wiki piece - specifically on the physical origins of the earth's magnetic field.