Dynamically adding filters

I think you are on the right track, but that last part is messy.
You are using the bw_add_markup_class function for two different purposes :

  • to return the classes that you want to add
  • to list the context of the filters that you want to call

If I understand well want you are trying to do, you need a function to return the array and then apply your modifications separately:

<?php
/**
 * Default array of classes to add separated from bw_add_markup_sanitize_classes()
 * This allows it to be used several places
 */
function bw_merge_genesis_attr_classes()
{
    $classes = array(
            'content-sidebar-wrap'      => 'row',
            'content'                   => 'col-xs-12 col-sm-8 col-lg-7 col-lg-offset-1',
            'sidebar-primary'           => 'hidden-xs col-sm-4 col-lg-3',
            'archive-pagination'        => 'clearfix',
            'entry-content'             => 'clearfix',
            'entry-pagination'          => 'clearfix',
            'sidebar-secondary'         => '',
    );
    if (has_filter('bw_add_classes')) {
        $classes = apply_filters('bw_add_classes', $classes);
    }
    return $classes;
}

/**
 * Adds Filters Automatically from Array Keys
 */
add_action('genesis_meta', 'bw_add_array_filters_genesis_attr');
function bw_add_array_filters_genesis_attr()
{
    $filters = bw_merge_genesis_attr_classes();
    foreach(array_keys($filters) as $context) {
        $context = "genesis_attr_$context";
        add_filter($context, 'bw_add_markup_sanitize_classes', 10, 2);
    }
}

/**
 * Clean classes output
 */
function bw_add_markup_sanitize_classes($attr, $context)
{
    $classes = array();
    if (has_filter('bw_clean_classes_output')) {
        $classes = apply_filters('bw_clean_classes_output', $classes, $context, $attr);
    }
    $value = isset($classes[$context]) ? $classes[$context] : array();
    if (is_array($value)) {
        $classes_array = $value;
    }
    else {
        $classes_array = explode(' ', (string)$value);
    }
    $classes_array = array_map('sanitize_html_class', $classes_array);
    $attr['class'].= ' ' . implode(' ', $classes_array);
    return $attr;
}

/**
 * Adds classes array to bsg_add_markup_class() for cleaning
 */
add_filter('bw_clean_classes_output', 'bw_modify_classes_based_on_extras', 10, 3);
function bw_modify_classes_based_on_extras($classes, $context, $attr)
{
    $classes = bw_merge_genesis_attr_classes($classes);
    return $classes;
}

Usage in template or elsewhere:

Now you can add classes to the array for cleaning and they will automatically be added to filters as well…

add_filter('bw_add_classes', 'bw_custom_example');
function bw_custom_example($classes) {
    $new_classes = array( 
        'nav-secondary'  => 'navbar navbar-inverse navbar-static-top nav-blue',
        'entry'          => 'panel panel-default',
    );
    return wp_parse_args($new_classes, $classes);
}