why do unlike poles attract while like poles repel?
This is the nature of poles that like poles repel and unlike poles attract each other.
In other sense, we can say that like poles produce same kind of magnetic field so they repel each other and unlike poles produce different kind of magnetic fields so they attract each other.