There is absolutely no reason that any company should be required to do this. Any company, or individual for that matter has the right to file suit. The court saw fit to hear the case, so it's clearly not some frivolous lawsuit and it wasn't an abuse of the courts--if it were, they could have thrown it out.
When you file suit, sometimes you win, sometimes you lose. In this case Apple lost. OK, fine, let the lawsuit end so both parties can go about their business.
A judge ordering a company to post a message like this is simply punishing them for exercising their rights. Losing the case (and all the financial issues that accompany that) should be enough.
This judge is sending a message, and it says: Don't sue people, don't try to protect your property. If you lose, not only will you lose the case, but you'll be publicly shamed for even trying.
Apple should have simply refused to comply with the order entirely. What is this judge going to do, demand extradition of Tim Cook from the US so he can do jail time for not saying he's sorry?