Since the primary goal is learning to code, you'll want to remove (for now) any other obstacles, so perhaps a Chromebook with the NextDNS[1] extension to filter against harmful content.
With a Chromebook, there's no having to fuss with anything else. He can focus on learning to code.
Web-based programming apps like Scratch, Replit, and JSFiddle work well with Chromebooks. We use them with our programming classes, and while I was initially skeptical, they've worked out really well, for years now.
We did try stuff like the Raspberry Pi, but didn't get much traction with students at the primary grade levels, it was too much setup and too much fiddling to grab their attention. They needed simple. We typically see more interest and success with Pis and Linux installs at the high school level.
1. https://my.nextdns.io/start (free/cheap)