How do I map a terminal command to a function key? I have a terminal command that can control my external display's brightness. I'm trying to map that command to a key on the keyboard so it works like a "brightness up" and "brightness down" key.

Karabiner doesn't look like it supports mapping keys to terminal commands
I am using karabiner-elements to do exactly this on a Dell monitor, you can bind keypresses to shell commands:

{
"title": "F5 to dim, F6 to bright",
"rules": [
    {
        "manipulators": [
            {
              "description": "dim",
              "type": "basic",
              "from": {
                "key_code": "f5"
              },
              "to": [
                {
                    "shell_command": "/usr/local/bin/ddcctl -d 1 -b 1"
                }
              ]
            },
            {
                "description": "bright",
                "type": "basic",
                "from": {
                  "key_code": "f6"
                },
                "to": [
                  {
                      "shell_command": "/usr/local/bin/ddcctl -d 1 -b 100"
                  }
                ]
              }
          ]
    }
]


}

(I have ddctl installed, which lets you control the brightness by passing it a percentage value - https://github.com/kfix/ddcctl )

You can check the docs for writing your Complex Modifications like this one: https://pqrs.org/osx/karabiner/json.html