No, that’s not exactly how it works. To install custom firmware, your phone must get bootloader unlock. In other words, it’s kinda unlocking the device itself, while applications like AFWall+ require root access, which is basically means unlocking the operation system.
There are several tools to perform root on your device. A few words about that are written HERE. (The first paragraph regarding Magisk, and the first comment under the guide.)