I am 32 years of age now. From ages 9-13, I lived in Germany on a valid residence permit as my father worked in the country. I am considering moving to Germany on a skilled worker's visa. I would like to understand if the time I spent as a child counts towards naturalization or towards long-term German EU residency.
In general, the requirement should be understood as having been a resident in the last X years, not merely having been a resident for X years over your lifetime. For the residence permit, there are somewhat complex rules under which a “former period” of residence could count but it wouldn't help in your case. For naturalisation, I don't see any explicit rules but I assume the logic is the same (i.e. only uninterrupted residence up to the time of application counts).
For EU long-term residence (a separate status), the language of the directive is even more explicit:
Member States shall grant long-term resident status to third-country nationals who have resided legally and continuously within its territory for five years immediately prior to the submission of the relevant application.
There are a few exceptions and additional rules for short interruptions but none that could cover a gap of 20 years.