It is not illegal, but it is EXPENSIVE to do this.
Because, you would have to go to the ATM and take a cash advance off of one card to pay the other. Credit card companies do not accept credit cards as a payment method. You can only use your bank account or debit card to do this. Once you take that cash advance, you are being charged a higher interest rate than you would for purchases, (usually 29% or higher) and you are charged a fee of up to 6% of the amount you just withdrew.
So, no, it isn't illegal, but it is a dumb way to pay your bills.