Insert a div class inside wordpress menu

I think use Custom Walker.

First register a custom navigation menu for this list in your theme’s functions.php

class WP_Walker extends Walker_Nav_Menu
{
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<div id='mega'><ul class="sub-menu">\n";
    }
    function end_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul></div>\n";
    }
}

After register custom navigation.
Usage below code in your theme:

wp_nav_menu(array ('theme_location' => 'your-theme-location', 'walker' => new WP_Walker));

Use a custom walker, extend the methods start_lvl() and end_lvl.

custom walker