It's not "illegal" under the law, but it may be forbidden by UA's Contract of Carriage, since you used your flight coupons out of order and returned to your origin city--if doing so made your flights cheaper, e.g. by getting around a minimum stay requirement (but unlike some others here, I don't think that circumventing a minimum stay requirement is the only way to break the rule against back-to-back ticketing). If your B fares are full fares, it should not be an issue, though, since the way in which you issued the tickets shouldn't have changed the price of a full-fare ticket.
But were they full fares? And what do you mean by "booked it this way for accounting
purposes"?
Did the CSR actually do something to you/your reservatin, in addition to yelling at you?