The values are in the QGIS3.ini and under QGIS, in the properties > Advanced tab > `core` > `Layout` > `searchPathsForTemplates`.

I modify the values with the following code :

<!-- language: py-lang -->

    new_template_dir = "/home/me/my_custom_template_dir"
    app = QgsApplication.instance()
    params = QgsSettings(
        app.qgisSettingsDirPath() + "QGIS/QGIS3.ini", QSettings.IniFormat
    )
    params.beginGroup("/core/Layout")
    # retrieve the current directories
    existing_dir = params.value("searchPathsForTemplates")
    # append the new one in the list
    if existing_dir is None:
        existing_dir = [new_template_dir]
    elif isinstance(existing_dir, str):
        if new_template_dir != existing_dir:
            existing_dir = [existing_dir, new_template_dir]
        else:
            existing_dir = [existing_dir]
    elif isintance(existing_dir, list):
        if new_template_dir not in existing_dir:
            existing_dir.append(new_template_dir)

    # setting the new list
    params.setValue("searchPathsForTemplates", existing_dir)

The code can be improved by verifying the `new_template_dir` exists for example but for me, it works.