Probably around the time they launched Swift Playgrounds, I have not checked. They set the rules, they get to change the rules. But the same rules still apply them as to everyone else.
There's no contradiction here. The App Store rules apply to everyone else wanting to publish something on the App Store. Obviously Apple has its own internal rules for what their own software can do.
Apple doesn’t need to say in the rules that they can do what they want, because they are the ones enforcing the rules. They can exempt anyone, including themselves, from the rules for any reason including no reason, without having to say anything about that in the rules. Human rules are not computer code, and also not mathematical. Human rules can be interpreted, bent and ignored. Sometimes at great risk, sometimes at no risk.
They don't, though, at least not in this case. There are special exemptions for educational programming software in the App Store, that covers Swift Playgrounds, but also others wanting to create similar things.
Here is an exercise, when a police patrol car gets parked in 2nd lane, and the officier happens to buying some stuff on a nearby shop, go there and tell them nicely that 2nd lane parking is against the traffic laws and they should fine themselves.
Broken analogy? Apple is the police of Apple store.
Plus the new feature of creating and packaging your iOS / iPadOS app + uploading it, directly on the iPad.
Apple seems to contradict its own rules since a few years now.