why like poles repel each other and unlike poles attract each other and why not like poles attract each other
Magnets attract or repulse because of tiny circulating currents comprising electrons inside them. It has been found that a single loop of current carrying wire is the simplest magnet with two poles. Upper side becomes the North Pole and lower is the South Pole.
It has also been found that two wires carrying current in the same direction attracts due to Lorentz’s force.
In the above we see that when the currents are in the same direction which makes attraction then South Pole of one loop faces the North Pole of the other. Thus unlike poles attract.
Similarly, it has also been found that two wires carrying current in the opposite direction repulses due to Lorentz’s force. Thus like poles repulse.