It can do that just fine, because it has seen enough examples of working code. It can’t directly count correctly, sure, but it can write “i++;”, incrementing a variable by one in a loop and returning the result. The computer running the generated program is going to be doing the counting.
It’s art. It’s not real, and it’s not hurting anybody in real life. We shouldn’t ban things because they make you uncomfortable, we ban them when they harm actual people.
Edit: this is in no way an endorsement of that particular fetish. I personally think it’s sick and disgusting. But it’s not my place to tell someone else not to enjoy it if nobody was harmed in its production.