yes, but illegal is a very big word. But you are right, according to the TOS it is not allowed.
If you read the Instagram TOS Instagram Help Center General conditions #10 it clearly says “We prohibit. otherwise accessing any content on the Service via automated means”.
They will not sue you for violating this, you will not end up in jail or so. But they can cancel/ban/delete your account.
Many people use automation to grow their accounts. If you stay within the limits the risks are small. But bad things can happen if you or the service you pay for are not careful.