I understand that imaginary numbers have turned out to be very useful but aren't there rules in mathematics that prevent you from inventing objects which, as far as I can see, contradict some mathematical rules?
To me, defining a number to be the $\sqrt{-1}$ is like defining a number that, when divided by zero, gives you $\pi$. Or defining a number to be "the largest prime number".
It's true that you can't (invent new mathematics that leads to a contradiction. (Or, better, shouldn't if you want your invention to be useful.)
Properly adding a square root of $-1$ to the set of things you call "numbers" does not lead to a contradiction. No rules are broken. The new "numbers" of the form $a+bi$ satisfy all the ordinary rules of arithmetic. None are broken.
It remains true that $-1$ has no square root in the original set, but that absence is not a "rule".
You can't add a number $q$ such that dividing it by $0$ gives you $\pi$ and still keep all the ordinary rules of arithmetic. If $q/0 = \pi$ then $q = 0 \times \pi = 0$ so $q$ wasn't a new number at all and doesn't do what you created it to do.