Companies buy shares of other companies from time to time!
In fact there is a SEC rule concerning the purchases of shares, that is acknowledgement of such purchases. It is called the 5 % rule.
After purchasing 5% of the shares of a company it must be reported to the SEC and then it is part of the record. Some companies only buy just under the 5% to avoid reporting.
As far as I know it is not illegal, unless the rules are not followed.