It happens that for 2 currents flowing in one direction it’s energy-wise more stable to be closer to each other - and wise versa.
Deep level answer: nobody knows why exactly is that.
Because electromagnetism is just a model to describe what we see with some math approximation.
Maybe it’s just we were lucky to be born in the universe with such properties and able to talk about it.
When electricity moves fast (close to the speed of light) relativistic effects occur which cause electric force to appear like (what we call) magnetic force.
So the real question is "Why do electrons use to react to each other?"
And the answer is, no one knows, no one can know, the best we can do is describe the behavior.
Physicists are forever talking about the beauty of the Standard Model of particle physics and how it can be explained in terms of QFT - Quantum Field Theory and so on but at the most basic level they still don't know what's actually in that field 'stuff' that 'glues' your fridge magnets to your fridge.
Have you noticed how this subject is so often avoided by physicists? Similarly, they also avoid the question 'what exactly is 'inside' a force that makes it do things?'.
Edit: several years ago Nobel prize winner Frank Wilczek was asked by New Scientist magazine what a field was and the best answer he could come up with was that it is a kind of matrix. At the time I thought this was a totally unsatisfactory answer.
In that reference frame, there are no magnetic fields that influence motion, just electrical charges attracting and repelling.
"It's just one of those things that you have to take as an element of the world.... I can't explain the attraction in terms of anything else that's familiar to you."